public static String encode(String s) {
if (s == null)
return null;
String res = "";
try {
res = new sun.misc.BASE64Encoder().encode(s.getBytes("utf-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return res;
}
/**
* 将 BASE64 编码的字符串 s 进行解码
*
* @return String
* @author lifq
* @date 2015-3-4 上午09:24:26
*/
public static String decode(String s) {
if (s == null)
return null;
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
return new String(b,"utf-8");
} catch (Exception e) {
return null;
}
}