/**
* Description 根据键值进行解密
*
* @return
*/
public static String decrypt(String data, String key) throws Exception {
if (data == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
byte[] buf = decoder.decodeBuffer(data);
byte[] bt = decrypt(buf, format(key));
return new String(bt, "UTF-8");
}
/**
* Description 根据键值进行解密
*
* @return
*/
public static byte[] decrypt2Byte(String data, String key) throws Exception {
if (data == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
byte[] buf = decoder.decodeBuffer(data);
return decrypt(buf, format(key));
}
/**
* Description 根据键值进行加密
*
* @return
*/
public static String encrypt(String data, String key) throws Exception {
byte[] bt = encrypt(data.getBytes("UTF-8"), format(key));
String strs = new BASE64Encoder().encode(bt);
return strs;
}
/**
* Description 根据键值进行加密
*
* @return
*/
public static String encrypt(byte[] bytes, String key) throws Exception {
byte[] bt = encrypt(bytes, format(key));
String strs = new BASE64Encoder().encode(bt);
return strs;
}
解决方案:
import java.util.Base64.Encoder;
import java.util.Base64.Decoder;
进行替换
/**
* Description 根据键值进行加密
*
* @return
*/
public static String encrypt(String data, String key) throws Exception {
byte[] bt = encrypt(data.getBytes("UTF-8"), format(key));
Encoder encoder = Base64.getEncoder();
return encoder.encodeToString(bt);
}
/**
* Description 根据键值进行加密
*
* @return
*/
public static String encrypt(byte[] bytes, String key) throws Exception {
byte[] bt = encrypt(bytes, format(key));
Encoder encoder = Base64.getEncoder();
return encoder.encodeToString(bt);
}
/**
* Description 根据键值进行解密
*
* @return
*/
public static String decrypt(String data, String key) throws Exception {
if (data == null)
return null;
Decoder decoder = Base64.getDecoder();
byte[] buf = decoder.decode(data);
byte[] bt = decrypt(buf, format(key));
return new String(bt, "UTF-8");
}
/**
* Description 根据键值进行解密
*
* @return
*/
public static byte[] decrypt2Byte(String data, String key) throws Exception {
if (data == null)
return null;
/*BASE64Decoder decoder = new BASE64Decoder();
byte[] buf = decoder.decodeBuffer(data);*/
Decoder decoder = Base64.getDecoder();
byte[] buf = decoder.decode(data);
return decrypt(buf, format(key));
}