无关风月
2025-02-11 f1b421b67ecf52431388d7b66e5e950d6d139ac4
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.taxi591.bankapi.utils;
 
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.io.UnsupportedEncodingException;
 
/**
 * 将String进行base64编码解码,使用utf-8
 * yuan
 */
public class Base64Util {
 
    private static final Logger LOGGER = LoggerFactory.getLogger(Base64Util.class);
    private static final String UTF_8 = "UTF-8";
 
    /**
     * 对给定的字符串进行base64解码操作
     */
    public static String decodeData(String inputData) {
        try {
            if (null == inputData) {
                return null;
            }
            return new String(Base64.decodeBase64(inputData.getBytes(UTF_8)), UTF_8);
        } catch (UnsupportedEncodingException e) {
            LOGGER.error(inputData, e);
        }
 
        return null;
    }
 
    /**
     * 对给定的字符串进行base64加密操作
     */
    public static String encodeData(String inputData) {
        try {
            if (null == inputData) {
                return null;
            }
            return new String(Base64.encodeBase64(inputData.getBytes(UTF_8)), UTF_8);
        } catch (UnsupportedEncodingException e) {
            LOGGER.error(inputData, e);
        }
 
        return null;
    }
 
}