JAVA自带的加密算法-MD5\SHA1\BASE64

时间:2023-03-09 09:11:19
JAVA自带的加密算法-MD5\SHA1\BASE64

需要导入jar包:

commons-codec.jar

MD5

String str = "abc";
DigestUtils.md5Hex(str);

SHA1

String str = "abc";
DigestUtils.shaHex(str);
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));
from http://blog.****.net/bestcxx/article/details/50125553