JAVA MD5加密Base64转码
时间: 2023-08-29 12:06:16 浏览: 51
下面是Java中使用MD5加密并进行Base64转码的示例代码:
```java
import java.security.MessageDigest;
import java.util.Base64;
public class MD5Util {
public static String encode(String str) throws Exception {
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] bytes = md5.digest(str.getBytes("UTF-8"));
String base64 = Base64.getEncoder().encodeToString(bytes);
return base64;
}
}
```
使用示例:
```java
public class Test {
public static void main(String[] args) throws Exception {
String str = "hello, world!";
String encodedStr = MD5Util.encode(str);
System.out.println(encodedStr);
}
}
```
输出结果:
```
Lve95gjOVATpfV8EL5X4nxwjKHE=
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.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)
![](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)
![](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)
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)