做解密操作,出现如下错误 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%jrelibsecurity目录下覆盖原来文件。