SpiritFryer
SpiritFryer

Reputation: 121

Java "Illegal key size" despite having installed JCE Unlimited Strength Jurisdiction Policy Files

I'm trying to use 256-bit AES encryption, but I am getting the following exception: java.security.InvalidKeyException: Illegal key size

If I use a 128-bit key, then everything works just fine.

I've installed the JCE Unlimited Strength Jurisdiction Policy Files by replacing the two .jar files at $JAVA_HOME$\jre\lib\security. I've tried different versions of these files. I've re-installed a newer version of Java 8 and updated the PATH environment variable. Nothing works. I still get the error, and Cipher.getMaxAllowedKeyLength("AES/CBC/NoPadding") still returns 128.

Upvotes: 0

Views: 978

Answers (1)

SpiritFryer
SpiritFryer

Reputation: 121

I'm on Windows 8. Originally I had Java 1.8.0_25 installed and there was only a single folder under C:\Program Files\Java which was jdk1.8.0_25. I was replacing the jar files at C:\Program Files\Java\jdk1.8.0_25\jre\lib\security. That didn't work.

After I installed the latest version (1.8.0_111), apart from the new jdk folder jdk1.8.0_111 a new folder appeared: jre1.8.0_111.

Replacing the two jar files in C:\Program Files\Java\jre1.8.0_111\lib\security fixed the problem. I also replaced the ones under C:\Program Files\Java\jdk1.8.0_111\jre\lib\security - I am not sure whether that was necessary or not, but it works.

Upvotes: 2

Related Questions