首页 > 其他 > 详细

备忘,commons-codec中可能用到的一些加密字符串的方法

时间:2016-04-15 00:39:13      阅读:261      评论:0      收藏:0      [点我收藏+]

commons-codec中提供了一些加密解密字符串的方法,我们可以直接使用

1.MD5加密:

String source = "source"

DigestUtils.md5Hex(source);

 

2.SHA1加密:

String str = "abc";

DigestUtils.shaHex(str);

 

3.BASE64加密/解密

//加密

String str= "abc"; // abc为要加密的字符串

byte[] b = Base64.encodeBase64(str.getBytes(), true);

System.out.println(new String(b));

//解密

String str = "YWJj"; // YWJj为要解密的字符串

byte[] b = Base64.decodeBase64(str.getBytes());

System.out.println(new String(b));

 

 

 

备忘,commons-codec中可能用到的一些加密字符串的方法

原文:http://www.cnblogs.com/jiaoyiping/p/5393511.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!