1. 加密和解密方法
@Slf4j
public class AESUtils {
/**
* AES加密
*
* @param key 密钥
* @param iv 偏移量
* @param data 需要加密的数据
*/
public static byte[] encrypt(String key, String iv, byte[] data) {
byte[] encrypted = {};
byte[] enCodeFormat = key.getBytes();
SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES");
try {
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, new IvParameterSpec(iv.getBytes()));
int blockSize = cipher.getBlockSize();
int plaintextLength = data.length;
if (plaintextLength % blockSize != 0) {
plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize));
}
byte[] plaintext = new byte[plaintextLength]