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

猜你喜欢

转载自blog.csdn.net/heming20122012/article/details/78155669