实现代码如下
/**BASE64加密
* @author 阿Sir
* @create:2021年4月4日 下午9:48:12
* @param key
* @return
*/
@SuppressWarnings("restriction")
public static String encryptBASE64(String key) throws Exception{
byte[] b = null;
String s = null;
try {
b = key.getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (b != null) {
s = new BASE64Encoder().encode(b);
}
return s;
}
/**BASE64解密
* @author 阿Sir
* @create:2021年4月4日 下午9:49:42
* @param key
* @return
* @throws IOException
*/
@SuppressWarnings("restriction")
public static String decryptBASE64(String key) throws Exception{
byte[] b = null;
String result = null;
if (key != null) {
BASE64Decoder decoder = new BASE64Decoder();
try {
b = decoder.decodeBuffer(key);
result = new String(b, "utf-8");
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}