Cryptography, Java

Fixing Illegal key size exception

If you are performing 256-bit AES encryption in Java, it is likely that you must be very familiar with this exception. Nothing to panic though. This exception is not your fault and you are not doing anything wrong. This exception is thrown because of a restriction imposed by default JDK. On a default JDK installation, AES is limited to 128 bit key size. In order to perform 256-bit AES encryption, you will need to download and install Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files. Here are the steps to fix Illegal key size exception:

1. Go to Oracle’s website and search for ‘Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files’.

2. Depending upon the Java version installed on your machine, download the zip file and extract it on your drive.

3. From the extracted folder, copy local_policy.jar and US_export_policy.jar files.

4. Go to your_java_installation_directory/jre/lib/security and paste the copied files. These files will already be there, you just need to copy and replace.

5. Refresh your project and you will not encounter this exception anymore.(fingers crossed) 🙂


10 thoughts on “Fixing Illegal key size exception

  1. hi devesh,

    i have put my jars in the server’s JDK. The error is still showing…any help on this?


  2. Hi devesh,
    i am having an error of “” at this line ” cipher.init(Cipher.ENCRYPT_MODE, keySpec);” at run time but not at compile time any solution on this ??

  3. Hi Devesh,
    This is a dated solution but worked perfectly for me – I was puzzled and thought the error was with Oracle OSB 12c server, but this seemed to be with the ‘Local_policy’ jar – thank you much.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s