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;
}
posted @ 2020-09-24 14:19  爱好编程的王能能  阅读(337)  评论(0编辑  收藏  举报