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));

 

 

 
posted on 2016-04-14 23:00  梦中彩虹  阅读(567)  评论(0编辑  收藏  举报