Example usage for org.apache.commons.codec.binary Base64 decodeBase64

List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Base64 decodeBase64.

Prototype

public static byte[] decodeBase64(final byte[] base64Data) 

Source Link

Document

Decodes Base64 data into octets

Usage

From source file:com.test.Base64Util.java

public static String decodeBase64(String message) {
    byte[] result = Base64.decodeBase64(message);
    return new String(result);
}

From source file:Logic.security.java

public static String symmetricEncrypt(String text, String secretKey) {
    byte[] raw;/*from ww  w .  j  ava2s  .c o m*/
    String encryptedString;
    SecretKeySpec skeySpec;
    byte[] encryptText = text.getBytes();
    Cipher cipher;
    try {
        raw = Base64.decodeBase64(secretKey);
        skeySpec = new SecretKeySpec(raw, "AES");
        cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
        encryptedString = Base64.encodeBase64String(cipher.doFinal(encryptText));
    } catch (Exception e) {
        e.printStackTrace();
        return "Error";
    }
    return encryptedString;
}

From source file:cn.zhuqi.mavenssh.ext.util.Coder.java

/**
 * BASE64/*from ww  w . jav a 2  s .  co  m*/
 *
 * @param key
 * @return
 * @throws Exception
 */
public static byte[] decryptBASE64(String key) throws Exception {
    return Base64.decodeBase64(key);
}

From source file:com.ykun.commons.utils.security.Base64Utils.java

/**
 * decode//from  ww  w .  j av  a 2 s.c o  m
 */
public static String decode(String data) {
    return org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.decodeBase64(data));
}

From source file:com.amazonaws.eclipse.core.accounts.preferences.PreferenceValueEncodingUtil.java

public static String decodeString(String s) {
    try {/*from   w ww  .j a va2  s. co m*/
        return new String(Base64.decodeBase64(s.getBytes("UTF-8")));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("Failed to decode the String", e);
    }
}

From source file:com.smart.common.FileHelper.java

public static boolean ConvertBase64ToImage(String Base64param, String filePath) {
    if (Base64param == null) // ??
    {/*from w  w  w .  j av a2s .  co  m*/
        return false;
    }
    //BASE64Decoder decoder = new BASE64Decoder();
    try {
        byte[] data = Base64.decodeBase64(Base64param);
        try (OutputStream stream = new FileOutputStream(filePath)) {
            stream.write(data);
            stream.close();
        }
        return true;
    } catch (Exception e) {
        RSLogger.ErrorLogInfo(String.format("ConvertBase64ToImage error: %s", e.getLocalizedMessage()), e);
        return false;
    }

}

From source file:net.cpollet.whereareyou.Base64Utils.java

public static byte[] toBytes(String string) {
    try {/*from  w  w  w. ja  v  a2s.c om*/
        return Base64.decodeBase64(string.getBytes("UTF-8"));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.taobao.ad.easyschedule.exsession.request.session.SessionDecode.java

public static String decode(String encoded) {
    String result = null;/*  w w w  . j a va2s.  c o m*/

    if (StringUtils.isNotBlank(encoded)) {
        try {
            byte[] decoded = Base64.decodeBase64(encoded.getBytes());

            result = new String(decoded);
        } catch (Exception e) {
            fLog.info(e.getMessage());
            result = "";
        }
    }

    return result;
}

From source file:ju.ehealthservice.graphs.ECGGraphImage.java

public static boolean save(String fileName, String img) {
    try {// ww w.  ja  v  a2 s  . c o  m
        StringBuffer data = new StringBuffer(img);
        data = new StringBuffer(data.substring(23));
        int c = 0;
        for (int i = 0; i < data.length(); i++) {
            if (data.charAt(i) == ' ') {
                c++;
                data.setCharAt(i, '+');
            }
        }
        byte[] imageByteArray = Base64.decodeBase64(data.toString());
        String ID = fileName.substring(0, fileName.indexOf('_'));
        String path = Constants.GRAPH_REPOSITORY_PATH + ID + "\\ECG\\";
        fileName = fileName + ".jpg";
        FileOutputStream imageOutFile = new FileOutputStream(path + fileName);
        imageOutFile.write(imageByteArray);
        imageOutFile.close();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:ju.ehealthservice.graphs.RespRateGraphImage.java

public static boolean save(String fileName, String img) {
    try {//from   ww w.  j  a va2  s . c o  m
        StringBuffer data = new StringBuffer(img);
        data = new StringBuffer(data.substring(23));
        int c = 0;
        for (int i = 0; i < data.length(); i++) {
            if (data.charAt(i) == ' ') {
                c++;
                data.setCharAt(i, '+');
            }
        }
        byte[] imageByteArray = Base64.decodeBase64(data.toString());
        String ID = fileName.substring(0, fileName.indexOf('_'));
        String path = Constants.GRAPH_REPOSITORY_PATH + ID + "\\RespRate\\";
        fileName = fileName + ".jpg";
        FileOutputStream imageOutFile = new FileOutputStream(path + fileName);
        imageOutFile.write(imageByteArray);
        imageOutFile.close();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}