<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.8</version>
</dependency>
SHA1加密,MD2加密,MD5加密
String pastSign = "abc";
String Str1= org.apache.commons.codec.digest.DigestUtils.sha1Hex(pastSign).toUpperCase();
String Str2 = org.apache.commons.codec.digest.DigestUtils.md2Hex(pastSign).toUpperCase();
String Str3 = org.apache.commons.codec.digest.DigestUtils.md5Hex(pastSign).toUpperCase();
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));