依赖

1
2
3
4
5
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>

1
org.apache.commons.codec.binary.Base64

编码

1
2
3
4
5
Base64.encodeBase64String(encrypted);

#老版本用法
import sun.misc.BASE64Encoder;
new BASE64Encoder().encode(encrypted);

解码

1
2
3
4
5
byte[] encrypted = Base64.decodeBase64(text);

#老版本用法
import sun.misc.BASE64Decoder;
byte[] encrypted1 = new BASE64Decoder().decodeBuffer(text);