0

I have installed JCE Unlimited strength to JAVA_HOME\lib\security
However, I'm still getting 128 for Cipher.getMaxAllowedKeyLength("AES").

I'm wondering if I have installed the JCE at the wrong place.
I have Java installed in 2 places.

  1. C:\Program Files\Java\jre7
  2. C:\Development\Java\jdk1.6.0_21

Can anyone tell me where is the correct place to install JCE Unlimited strength? Your help is much appreciated.

my code:

 KeyGenerator generator = KeyGenerator.getInstance("AES");      
 generator.init(256);       SecretKey secretKey = generator.generateKey();      
 byte[] raw= secretKey.getEncoded();        
 SecretKeySpec sskey= new SecretKeySpec(raw, "AES");

        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");         
        if (mode == Cipher.ENCRYPT_MODE) { 
           Cipher.getMaxAllowedKeyLength("AES"));   
           cipher.init(Cipher.ENCRYPT_MODE, sskey);             
           CipherInputStream cis = new CipherInputStream(is, cipher); 
           doCopy(cis, os);         
        } else if (mode == Cipher.DECRYPT_MODE) { 
           cipher.init(Cipher.DECRYPT_MODE, sskey); 
           CipherOutputStream cos = new CipherOutputStream(os, cipher);             
           doCopy(is, cos);         
        }
user3034683
  • 39
  • 3
  • 10
  • Can you show the code you used? It should only depend on the length of the key you use. – Henry Aug 15 '14 at 04:14

1 Answers1

3

You need to install the files into whichever JVM is going to run your code. To be on the safe side, I'd advocate installing it in both.

I notice you have two different versions: Java 7 for a JRE and Java 6 for an SDK. Bear in mind that Java 6 and 7 have different unlimited strength policy files, so you'll need to download both sets.

  • For the JRE, install into C:\Program Files\Java\jre7\lib\security.
  • For the JDK, install into C:\Development\Java\jdk1.6.0_21\jre\lib\security.
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • How to determine which JVM is running my code? I have actually installed the correct versions to the both sets, but still getting the error. – user3034683 Aug 15 '14 at 07:27
  • @user3034683 It depends how you are running it. If it's from an IDE, you'll need to dig into the settings and see what is being used. If it's from the command line, then the first Java executable on your `%PATH%` is being used. Try running it from the command-line and specifically try each of your JVMs. Note, you won't be able to run anything in Java 6 that was compiled for Java 7. – Duncan Jones Aug 15 '14 at 07:31
  • Can you also add your stack trace to your question, just in case we've got a slightly different problem going on? – Duncan Jones Aug 15 '14 at 07:32
  • thanks for your reply. If i'm running the encryption in a test server, should the server be set up with the JCE Unlimited strength policy? – user3034683 Aug 15 '14 at 08:18
  • 1
    @user3034683 Yes. Everywhere you want to run this, you must have those policy files installed. – Duncan Jones Aug 15 '14 at 08:19
  • 1
    You can look through the [system properties](http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html) from within the source, it should contain the information about the current JRE. – Maarten Bodewes Aug 15 '14 at 13:27