xieb
2023-10-19 1dd5d8f8a616f5cf3caa7828d46989c7d3dcafc4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package cn.gistack.common.utils;
 
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
 
public class Base64Utils {
 
    // 加密
    public static String getBase64Encode(String str) {
        // String-->byte[]
        byte [] data = str.getBytes(StandardCharsets.UTF_8);
        // 编码(base64字符串)
        String base64Str = Base64.getEncoder().encodeToString(data);
        return base64Str;
    }
 
    /**
     * 对Base64字符串进行解码
     * @param base64Str
     * @return
     */
    public static String getBase64Decode(String base64Str) {
// 解码
        byte [] base64Data = Base64.getDecoder().decode(base64Str);
        // byte[]-->String(解码后的字符串)
        String str = new String(base64Data, StandardCharsets.UTF_8);
        return str;
    }
}