java的hex_md5加密
时间: 2023-11-11 21:22:45 浏览: 149
Java中的hex_md5加密可以使用MessageDigest类实现。以下是示例代码:
```java
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Util {
public static String hex_md5(String input) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(input.getBytes());
byte[] digest = md.digest();
StringBuilder sb = new StringBuilder();
for (byte b : digest) {
sb.append(String.format("%02x", b & 0xff));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
}
```
使用方法:
```java
String input = "hello world";
String md5 = MD5Util.hex_md5(input);
System.out.println(md5);
```
输出结果:
```
5eb63bbbe01eeed093cb22bb8f5acdc3
```
阅读全文