新增MD5Util
This commit is contained in:
parent
84fcf2fa68
commit
cbfb868ec0
36
cloud-common/src/main/java/com/cm/common/utils/MD5Util.java
Normal file
36
cloud-common/src/main/java/com/cm/common/utils/MD5Util.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package com.cm.common.utils;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When you feel like quitting. Think about why you started
|
||||||
|
* 当你想要放弃的时候,想想当初你为何开始
|
||||||
|
*
|
||||||
|
* @ClassName: MD5Util
|
||||||
|
* @Description: MD5处理
|
||||||
|
* @Author: WangGeng
|
||||||
|
* @Date: 2020/6/30 12:20 上午
|
||||||
|
* @Version: 1.0
|
||||||
|
**/
|
||||||
|
public class MD5Util {
|
||||||
|
|
||||||
|
public static String toMD5String(String str) throws NoSuchAlgorithmException {
|
||||||
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||||
|
if (md != null && str != null) {
|
||||||
|
byte[] byteData = md.digest(str.getBytes(Charset.forName("UTF-8")));
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
byte[] var4 = byteData;
|
||||||
|
int var5 = byteData.length;
|
||||||
|
|
||||||
|
for (int var6 = 0; var6 < var5; ++var6) {
|
||||||
|
byte aByteData = var4[var6];
|
||||||
|
sb.append(Integer.toString((aByteData & 255) + 256, 16).substring(1));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user