forked from zhuzhegithub/utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBase64Utils.java
More file actions
47 lines (41 loc) · 1.1 KB
/
Base64Utils.java
File metadata and controls
47 lines (41 loc) · 1.1 KB
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.space.utils.encrypt;
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Decoder;
import java.io.IOException;
public class Base64Utils {
/**
* 加密
* 加密byte[]类型,密文为字符串
* @param b
* @return
*/
public static String encodeByte(byte[] b) {
return new String(new Base64().encode(b));
}
/**
* 解密
* 将字符串解密为String类型
* @param source
* @return
*/
public static String decodeToByte(String source) {
return new String(new Base64().decode(source.getBytes()));
}
/**
* 解密
* 将字符串解密为String类型
* @param s
* @param charSet 字符编码
* @return
*/
public static String getFromBase64(String s,String charSet) throws IOException {
byte[] b = null;
String result = null;
if (s != null) {
BASE64Decoder decoder = new BASE64Decoder();
b = decoder.decodeBuffer(s);
result = new String(b, charSet);
}
return result;
}
}