2025-07-05 18:08:31 +08:00

44 lines
1.0 KiB
Java

package com.zhgd.xmgl;
import org.apache.http.util.TextUtils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Md5Utils {
public static void main(String[] args) {
System.out.println(md5ForMCS8("mcs8@666"));
}
/**
* MCS8根据密码获取token
*
* @param string
* @return
*/
public static String md5ForMCS8(String string) {
if (TextUtils.isEmpty(string)) {
return "";
}
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("MD5");
byte[] bytes = md5.digest(string.getBytes());
String result = "";
for (byte b : bytes) {
String temp = Integer.toHexString(b & 0xff);
if (temp.length() == 1) {
temp = "0" + temp;
}
result += temp;
}
return result;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
}