Using stronger security algorithms

Lets use AES-256 – we simply change the key to a length of 256 bits:

String key = "Bar12345Bar12345Bar12345Bar12345"; // 256 bit key

This results in the following exception: Illegal key size or default parameters

To solve this and enable the use use of longer keys, it is necessary to download and install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files.

First, download the file from

Make sure that you download the right version for your JRE (either 6 or 7). If you are using the policy files with a wong JRE version, you will get the following exception:

java.lang.SecurityException: Jurisdiction policy files are not signed by trusted signers!

The zip file contains two jar files and a README.txt file. Read through the README.txt file for additional information. 

If you want to revert to the default restricted policy files at a later time, make a backup of the existing $JRE_HOME/lib/security/local_policy.jar and $JRE_HOME/lib/security/US_export_policy.jar files. Then install the unrestricted policy files by copying the two jar files from the zip file to your $JRE_HOME/lib/security directory.

After installing these files, the sample application will now also run with an 256 bit AES key.