Base64加密解密util

来源:互联网 发布:中国超级高铁计划知乎 编辑:程序博客网 时间:2024/06/11 07:43
import java.io.UnsupportedEncodingException;


import org.apache.commons.codec.binary.Base64;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * 将String进行base64编码解码,使用utf-8
 */
public class Base64Util {


private static final Log logger = LogFactory.getLog(Base64Util.class);


/**
* 对给定的字符串进行base64解码操作
*/
public static String decodeData(String inputData) {
try {
if (null == inputData) {
return null;
}
return new String(Base64.decodeBase64(inputData.getBytes("utf-8")), "utf-8");
} catch (UnsupportedEncodingException e) {
logger.error(inputData, e);
}


return null;
}


/**
* 对给定的字符串进行base64加密操作
*/
public static String encodeData(String inputData) {
try {
if (null == inputData) {
return null;
}
return new String(Base64.encodeBase64(inputData.getBytes("utf-8")), "utf-8");
} catch (UnsupportedEncodingException e) {
logger.error(inputData, e);
}


return null;
}


}
0 0