gradle 添加引用
dependencies {
compile group: 'commons-codec', name: 'commons-codec', version: '1.10'
}
方法:
1 import org.apache.commons.codec.binary.Base64;
2
3 import java.io.UnsupportedEncodingException;
4
5 /**
6 * Created by Z on 2016/11/18.
7 */
8 public class TestMain {
9 public static void main(String[] args) throws UnsupportedEncodingException {
10 String name = "抗压吧务团队5";
11 byte[] b = name.getBytes("utf-8");
12 String encode = Base64.encodeBase64String(b);
13 String decode = new String(Base64.decodeBase64(encode));
14 byte[] decode2 = Base64.encodeBase64(b);
15 byte[] decode3 = Base64.decodeBase64(decode2);
16 System.out.println(encode);
17 System.out.println(decode);
18 System.out.println(new String(decode3));
19 }
20 }
其他方法:
输出:
5oqX5Y6L5ZCn5Yqh5Zui6ZifNQ==
抗压吧务团队5
抗压吧务团队5