赞
踩
在项目过程中,用到对某段字符串进行BASE64加密,然后百度了下,找到解决方案,并记录下来,加深印象。
使用到的jar包:import sun.misc.BASE64Decoder;
// 将 s 进行 BASE64 编码
public static String getBASE64(String s) {
if (s == null)
return null;
return (new sun.misc.BASE64Encoder()).encode( s.getBytes() );
}
// 将 BASE64 编码的字符串 s 进行解码
public static String getFromBASE64(String s) {
if (s == null) return null;
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
return new String(b);
} catch (Exception e) {
return null;
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。