package com.walker.security;
|
|
//import org.apache.commons.codec.binary.Base64;
|
|
public class Base64Utils {
|
|
/**
|
* <p>
|
* BASE64字符串解码为二进制数据
|
* </p>
|
*
|
* @param base64
|
* @return
|
* @throws Exception
|
*/
|
public static byte[] decode(String base64) throws Exception {
|
// return Base64.decodeBase64(base64.getBytes());
|
return Base64.decode(base64.getBytes());
|
}
|
|
public static byte[] decode(byte[] value){
|
// return Base64.decodeBase64(value);
|
return Base64.decode(value);
|
}
|
|
/**
|
* <p>
|
* 二进制数据编码为BASE64字符串
|
* </p>
|
*
|
* @param bytes
|
* @return
|
* @throws Exception
|
*/
|
public static String encode(byte[] bytes) throws Exception {
|
return new String(Base64.encodeBase64(bytes));
|
}
|
|
public static byte[] encodeString(String value){
|
return Base64.encodeBase64(value.getBytes());
|
}
|
|
public static String decodeByte(byte[] value){
|
return new String(Base64.decodeBase64(value));
|
}
|
|
}
|