shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
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
package com.walker.security;
 
//import org.apache.commons.codec.binary.Base64;
 
public class Base64Utils {
 
     /**
     * <p>
     * BASE64字符串解码为二进制数据
     * </p>
     * 
     * @param base64
     * @return
     * @throws Exception
     */
    public static byte[] decode(String base64) throws Exception {
//        return Base64.decodeBase64(base64.getBytes());
        return Base64.decode(base64.getBytes());
    }
    
    public static byte[] decode(byte[] value){
//        return Base64.decodeBase64(value);
        return Base64.decode(value);
    }
    
    /**
     * <p>
     * 二进制数据编码为BASE64字符串
     * </p>
     * 
     * @param bytes
     * @return
     * @throws Exception
     */
    public static String encode(byte[] bytes) throws Exception {
        return new String(Base64.encodeBase64(bytes));
    }
    
    public static byte[] encodeString(String value){
        return Base64.encodeBase64(value.getBytes());
    }
    
    public static String decodeByte(byte[] value){
        return new String(Base64.decodeBase64(value));
    }
 
}