SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");// 生成密匙
byte[] encrypted1 = new BASE64Decoder().decodeBuffer(data);
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");// 创建密码器
IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);// 初始化
byte[] original = cipher.doFinal(encrypted1);
String originalString = new String(original, "UTF-8");
public static String decValueBySecretKey(String sourcedata,SecretKeySpec symmetricKey) throws Exception{
// 解密被加密的项,可使用对称密钥对多个加密项进行解密
Cipher cipher = Cipher.getInstance("AES");// 创建密码器
cipher.init(Cipher.DECRYPT_MODE, symmetricKey);
byte[] result = cipher.doFinal(Base64.decode(sourcedata));
String decryptedData = new String(result,"UTF-8");
return decryptedData;
}