`
huoyanyanyi10
  • 浏览: 52513 次
  • 性别: Icon_minigender_1
  • 来自: 赤峰
社区版块
存档分类
最新评论

java Base64加解密

    博客分类:
  • java
阅读更多
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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics