码迷,mamicode.com
首页 > 其他好文 > 详细

使用commons-codec包加密字符串(MD5,SHA1,BASE64)

时间:2015-10-28 12:20:07      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:

1. [代码]MD5 

String str = "abc";
DigestUtils.md5Hex(str);
 
//附.net生成MD5的方法,生成内容跟java一致:
String str = "abc";
FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");

2. [代码]SHA1

String str = "abc";
DigestUtils.shaHex(str);
 
//附.net生成SHA1的方式,生成内容跟java一致:
String str = "abc";
FormsAuthentication.HashPasswordForStoringInConfigFile(str, "SHA1");

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包加密字符串(MD5,SHA1,BASE64)

标签:

原文地址:http://www.cnblogs.com/shenyixin/p/4916605.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!