package com.xj.hhjk.common.util.security;
import java.security.GeneralSecurityException;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class AesUtil {
public static byte[] decrypt(byte[] content, byte rawKeyData[]) throws GeneralSecurityException {
// 处理密钥
SecretKeySpec key = new SecretKeySpec(rawKeyData, 0, 16, "AES");
// 解密,创建密码器
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");//
// 初始化
cipher.init(Cipher.DECRYPT_MODE, key);
return cipher.doFinal(content);
}
public static byte[] encrypt(byte[] source, byte rawKeyData[]) throws GeneralSecurityException {
SecretKeySpec key = new SecretKeySpec(rawKeyData, "AES");// 处理密钥
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");// 加密
cipher.init(Cipher.ENCRYPT_MODE, key);
return cipher.doFinal(source);
}
}