public static String md5(String target) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
byte[] bytes = messageDigest.digest(target.getBytes());
StringBuffer sb = new StringBuffer();
for (byte b : bytes) {
int i = b & 0xff;
String hexString = Integer.toHexString(i);
if (hexString.length() < 2) {
hexString = "0" + hexString;
}
sb.append(hexString);
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
Java,MD5
最新推荐文章于 2025-03-03 00:15:00 发布
本文介绍了一种使用Java实现的MD5加密算法。通过实例展示了如何将字符串转换为MD5格式,包括获取MessageDigest实例、进行字节转换及十六进制字符串拼接等关键步骤。
2146

被折叠的 条评论
为什么被折叠?



