public class Base64Util { // 把普通字符编码成64bit public static String strToBase64(String s) throws UnsupportedEncodingException { if (s == null) return null; return (new sun.misc.BASE64Encoder()).encode(s.getBytes("UTF-8")); }
// 把64bit编码转化成普通字符串 public static String base64ToStr(String s) { if (s == null) return null; BASE64Decoder decoder = new BASE64Decoder(); try { byte[] b = decoder.decodeBuffer(s); return new String(b, "UTF-8"); } catch (Exception e) { return null; } }