解决方案:
添加maven:
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.55</version>
</dependency>
下载jce_policy-8.zip压缩包
下面为下载链接
For Oracle JDK 1.7
https://files.cnblogs.com/files/zgngg/UnlimitedJCEPolicyJDK7.zip
For Oracle JDK 1.8
https://files.cnblogs.com/files/zgngg/jce_policy-8.zip
把压缩包中local_policy.jar、US_export_policy.jar替换到JDK安装目录的jre\lib\security目录下。
最后一步
在Cipher instance = Cipher.getInstance(“AES/CBC/PKCS7Padding”);之前添加
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
让其支持PKCS7Paddin
案例
public static byte[] e(SecretKeySpec secretKeySpec, byte[] bArr, byte[] bArr2) throws GeneralSecurityException {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
Cipher instance = Cipher.getInstance("AES/CBC/PKCS7Padding");
instance.init(1, secretKeySpec, new IvParameterSpec(bArr));
byte[] doFinal = instance.doFinal(bArr2);
h("cipherText", doFinal);
return doFinal;
}