2

I'm trying to decrypt on Java, a encrypted string on JavaScript with CryptoJS AES, as explained on this post.

But I have come to an impasse, where I have already installed the Unlimited Strength Jurisdiction Policy as explained on this post, where you only have to replace the JCE files you already have in your $javahome/jre/lib/security.

If i do sudo update-alternatives --config java, I get the current jvm:

* 2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 modo manual

So I'm replacing the files at /usr/lib/jvm/java-8-oracle/jre/lib/security/.

I restarted my computer to make sure java restarted and I still got the Illegal key size exception.

The project is on NetBeans, and runs with a Tomcat, the only thing that bothers me, is that the source/binary of the project is JDK 7, which I don't know if it may be the reason for the exception or not.

If it is so, how do I know what JCE files I have to replace? I can't move the source/binary, I mean, I can, but I can't do it on production, it has to work as it is.

If that isn't the reason, how do I solve this problem?

Community
  • 1
  • 1
Lauro182
  • 1,597
  • 3
  • 15
  • 41

1 Answers1

2

You can use the following snippets to help debug the issue:

Cipher.getMaxAllowedKeyLength("AES"); // Will return 128 in "limited" mode; Integer.MAX_VALUE in "unlimited"

System.getenv("JAVA_HOME"); // Gets the Java home path as set in the OS environment -- in this case should be /usr/lib/jvm/java-8-oracle/
System.getProperty("java.home"); // Gets the JRE home path -- in this case should be /usr/lib/jvm/java-8-oracle/jre

System.getenv("PATH"); // Gets the current PATH variable from the OS environment
System.getProperty("java.class.path"); // Gets the Java classpath

System.getProperty("java.version"); // Gets the JRE version number of the current JVM

Putting those statements in Java code that is executed by Tomcat will give you the information about the context in which Tomcat is running. You can also run the following commands from the terminal in order to ensure you are using the same JRE when you edit the JCE USC jurisdiction policy files.

$ echo $JAVA_HOME   # prints the OS' Java home path
$ which java        # prints the java executable that is found in the path

There is no need to restart the computer after modifying these policies, just the JRE.

Andy
  • 13,916
  • 1
  • 36
  • 78