Base64转码

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;
    }
}
posted @ 2021-06-18 11:26  瓦刀哥  阅读(109)  评论(0编辑  收藏  举报