Home >Java >javaTutorial >How to Resolve the Java Cryptography Exception: 'Illegal Key Size'?
Java Cryptography Exception: "Illegal Key Size"
The "InvalidKeyException: Illegal key size" error typically occurs when Java's security policy restricts the use of strong cryptography due to US export laws. This can prevent certain encryption algorithms from being used on systems running outside of the United States.
Java 9 and Above
Java 9 and later versions include the Unlimited Strength Jurisdiction Policy Files by default. However, if this error persists, it may indicate a configuration change that has reintroduced the limitation. Refer to the Security Updates in the Java 9 Migration Guide for steps on how to restore the unlimited strength policy.
Java 8 and Below
Java 8 Update 161 and Higher
Java 8 Update 161 and above default to the Unlimited Strength Jurisdiction Policy. If the error occurs, it could imply a switch to a more restrictive policy. Follow the instructions outlined in the previous section for Java 9 to revert back to unlimited strength.
Java 8 Update 151 and Higher
Java 8 Update 151 includes the Unlimited Strength Jurisdiction Policy, but it is not used by default. To enable it, modify the java.security file by uncommenting (or including) the following line in /jre/lib/security or /lib/security based on your JDK/JRE installation:
crypto.policy=unlimited
Restart the JVM after making the changes for them to take effect.
Before Java 8 Update 151
For Java 8 Update 144 and earlier, the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files must be installed manually. Download these files from Oracle and follow the README.txt instructions:
The above is the detailed content of How to Resolve the Java Cryptography Exception: 'Illegal Key Size'?. For more information, please follow other related articles on the PHP Chinese website!