java开发DM5加密
时间: 2023-08-27 20:03:54 浏览: 52
在Java中使用MD5加密可以使用以下代码:
```
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Encryptor {
public static String encrypt(String stringToEncrypt) {
StringBuilder sb = new StringBuilder();
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(stringToEncrypt.getBytes());
byte[] bytes = md.digest();
for (byte b : bytes) {
sb.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return sb.toString();
}
}
```
使用该类中的`encrypt`方法即可对需要加密的字符串进行MD5加密。例如:
```
String encryptedString = MD5Encryptor.encrypt("hello world");
System.out.println(encryptedString);
```
输出结果为:
```
5eb63bbbe01eeed093cb22bb8f5acdc3
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)