java md532位小写加密
时间: 2023-12-31 20:23:55 浏览: 74
以下是两种Java实现MD5 32位小写加密的方法:
方式一:Java自身包实现
```java
import java.math.BigInteger;
import java.security.MessageDigest;
public static String md5(String str) {
byte[] secretBytes = null;
try {
secretBytes = MessageDigest.getInstance("md5").digest(str.getBytes());
} catch (Exception e) {
throw new RuntimeException("没有这个md5算法!");
}
String md5code = new BigInteger(1, secretBytes).toString(16);
for (int i = 0; i < 32 - md5code.length(); i++) {
md5code = "0" + md5code;
}
return md5code;
}
```
方法二:apache提供的加密包commons-codec
```java
import org.apache.commons.codec.digest.DigestUtils;
public static String md52(String plainText) {
try {
return DigestUtils.md5Hex(plainText.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
}
```
阅读全文