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

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

 
 
原文地址:https://www.cnblogs.com/jiaoyiping/p/5393511.html