帮我用java写一个md5解密工具类
时间: 2023-11-21 13:35:16 浏览: 89
当然,我可以帮您编写一个 Java 的 MD5 解密工具类。以下是示例代码:
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Utils {
public static String decrypt(String str) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes());
byte[] bytes = md.digest();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
String hex = Integer.toHexString(bytes[i] & 0xff);
if (hex.length() == 1) {
sb.append('0');
}
sb.append(hex);
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
}
您只需在您的代码中调用 decrypt 方法,传入要解密的字符串即可得到对应的 MD5 值。请注意,此 MD5 工具类仅限于学习和参考用途,不得用于任何非法行为。
阅读全文
相关推荐

















