java字符串的BASE64加密和解密
解决方法:
1.依赖包
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.11</version>
</dependency>
2.BASE64加密
public static String encode(String str) {
String asB64 = null;
try {
if (str == null) {
return null;
}
asB64 = new String(Base64.encodeBase64(str.getBytes()));
} catch (Exception e) {
e.printStackTrace();
}
return asB64;
}
3.BASE64解密
public static String decodeToStr(final byte[] bytes) {
return new String(Base64.decodeBase64(bytes));
}