38 lines
973 B
Java
38 lines
973 B
Java
package cn.shangyu.gdxzExpert.utils;
|
|
|
|
import java.security.MessageDigest;
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
/**
|
|
* Created by 12457 on 2017/8/2.
|
|
*/
|
|
|
|
public class Md5Tool {
|
|
|
|
private static String bytesToHexString(byte[] bytes) {
|
|
StringBuilder sb = new StringBuilder();
|
|
for (int i = 0; i < bytes.length; i++) {
|
|
String hex = Integer.toHexString(0xFF & bytes[i]);
|
|
if (hex.length() == 1) {
|
|
sb.append('0');
|
|
}
|
|
sb.append(hex);
|
|
}
|
|
return sb.toString();
|
|
}
|
|
|
|
public static String hashKey(String key) {
|
|
String hashKey;
|
|
try {
|
|
final MessageDigest mDigest = MessageDigest.getInstance("MD5");
|
|
mDigest.update(key.getBytes());
|
|
hashKey = bytesToHexString(mDigest.digest());
|
|
} catch (NoSuchAlgorithmException e) {
|
|
hashKey = String.valueOf(key.hashCode());
|
|
}
|
|
return hashKey;
|
|
}
|
|
|
|
}
|