Java base64的加密与解密

写在前面:参考https://www.cnblogs.com/alter888/p/9140732.html

final Base64.Decoder decoder = Base64.getDecoder();
final Base64.Encoder encoder = Base64.getEncoder();

//加密
public static String encode(String text) {
byte[] textByte = new byte[0];
try {
textByte = text.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String encodedText = encoder.encodeToString(textByte);
return encodedText;
}
//解密
public static String decode(String encodedText) {
String text = null;
try {
text = new String(decoder.decode(encodedText), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return text;
}
原文地址:https://www.cnblogs.com/wnnstudy/p/13723847.html