java Base64加解密

import sun.misc.BASE64Decoder;


public class Test {
//BASE64编码
public static String getBASE64(String str) {
  if (str == null)
   return null;
  return (new sun.misc.BASE64Encoder()).encode(str.getBytes());
}

//BASE64解码
public static String getFromBASE64(String str) {
  if (str == null)
   return null;
  BASE64Decoder decoder = new BASE64Decoder();
  try {
   byte[] b = decoder.decodeBuffer(str);
   return new String(b);
  } catch (Exception e) {
   return null;
  }
}

public static void main(String[] args) {
  String str = "中国";
  str = getBASE64(str);
  System.out.println(str);
  str = getFromBASE64(str);
  System.out.println(str);
}

}

友情链接:珀莱雅  欧诗漫  专卖 http://store.taobao.com/shop/view_shop.htm?mytmenu=mdianpu&utkn=g,2djlrizuga4a1324992712104&user_number_id=372143050

你可能感兴趣的:(java Base64加解密,Base64加解密)