Illegal key size or default parameters

简介: java中使用AES对称加密后,请求报错:Caused by: java.lang.RuntimeException: java.security.InvalidKeyException: Illegal key size or default parameters at com.

java中使用AES对称加密后,请求报错:

Caused by: java.lang.RuntimeException: java.security.InvalidKeyException: Illegal key size or default parameters
        at com.btzh.util.AESUtil.encrypt(AESUtil.java:18)
        at com.btzh.service.impl.SiThirdSystemServiceImpl.mapSystemParams(SiThirdSystemServiceImpl.java:32)
        at com.btzh.resource.SiThirdSystemResource.mapSystemParams(SiThirdSystemResource.java:41)
        ... 43 common frames omitted
Caused by: java.security.InvalidKeyException: Illegal key size or default parameters
        at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1026)
        at javax.crypto.Cipher.implInit(Cipher.java:801)
        at javax.crypto.Cipher.chooseProvider(Cipher.java:864)
        at javax.crypto.Cipher.init(Cipher.java:1249)
        at javax.crypto.Cipher.init(Cipher.java:1186)
        at com.btzh.util.AESUtil.encrypt(AESUtil.java:15)

原因是美国的出口限制,Sun通过权限文件(local_policy.jar、US_export_policy.jar)做了相应限制。密钥长度最大128,对于需要更大长度的场景则会抛出上面异常。

解决办法是下载Oracle官方网站上的无政策限制权限文件,下载链接:

jdk8:https://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

下载后将%JAVA_HOME%\jre\lib\security中的local_policy.jarUS_export_policy.jar替换为下载包中的的local_policy.jarUS_export_policy.jar

目录
相关文章
|
XML SQL 数据库
Error getting generated key or setting result to parameter object.必须执行该语句才能获得结果。
Error getting generated key or setting result to parameter object.必须执行该语句才能获得结果。
2728 47
|
SQL
Parameter ‘id‘ not found. Available parameters are [collection, list]
Parameter ‘id‘ not found. Available parameters are [collection, list]
236 0
错误代码: 1364 Field ‘password‘ doesn‘t have a default value
错误代码: 1364 Field ‘password‘ doesn‘t have a default value
Optional int parameter ‘id‘ is present but cannot be translated into a null value due to being ……
Optional int parameter ‘id‘ is present but cannot be translated into a null value due to being ……
305 0
|
Windows
Illegal character in opaque part at index
Illegal character in opaque part at index
成功解决TypeError: Value passed to parameter 'paddings' has DataType float32 not in list of allowed valu
成功解决TypeError: Value passed to parameter 'paddings' has DataType float32 not in list of allowed valu