java md5 32位小写
时间: 2023-12-30 07:04:07 浏览: 103
以下是Java实现MD5 32位小写加密的代码示例:
```java
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Example {
public static void main(String[] args) {
String str = "Hello World";
String md5code = md5(str);
System.out.println("MD5 value: " + md5code);
}
public static String md5(String str) {
byte[] secretBytes = null;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes());
secretBytes = md.digest();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("No such algorithm: MD5");
}
BigInteger bigInt = new BigInteger(1, secretBytes);
String md5code = bigInt.toString(16);
while (md5code.length() < 32) {
md5code = "0" + md5code;
}
return md5code;
}
}
```
阅读全文