/**
* MD5 加码 32位
*
* @param plainText plainText
* @return result
*/
public static String toMD5(String plainText) {
String result = "";
MessageDigest md = null;
try {
// 获取 MD5转换器 (可以换成"SHA1")
md = MessageDigest.getInstance("MD5");
md.update(plainText.getBytes());
byte[] b = md.digest();
int i;
StringBuilder sb = new StringBuilder("");
for (byte value : b) {
i = value;
if (i < 0) {
i += 256;
}
if (i < 16) {
sb.append("0");
}
sb.append(Integer.toHexString(i));
}
result = sb.toString();
} catch (NoSuchAlgorithmException e) {
log.error("com.jointech.business.utils.BusinessCommonUtils.toMD5 Exception:" + e.getMessage());
return "";
}
return result;
}
java自带的MD5加密
最新推荐文章于 2024-06-30 14:03:42 发布