做解密操作,出现如下错误 java.security.InvalidKeyException: Illegal key size
// 设置解密模式为AES的CBC模式 Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); SecretKeySpec key_spec = new SecretKeySpec(aesKey, "AES"); IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(aesKey, 0, 16)); cipher.init(Cipher.DECRYPT_MODE, key_spec, iv);
异常原因:如果密钥大于128, 会抛出java.security.InvalidKeyException: Illegal key size 异常
解决方法:JDK7的下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html
将两个jar文件放到%JDK_HOME%\jre\lib\security目录下覆盖原来文件。
参考:https://www.cnblogs.com/lilinzhiyu/p/8024100.html
原文地址:https://www.cnblogs.com/linlf03/p/9429861.html
时间: 2024-09-30 15:37:11