Skip to content

Instantly share code, notes, and snippets.

@4ndrej
Forked from nogweii/Test.java
Created October 14, 2019 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4ndrej/75bb405418f451ca245e00095c6f8b4c to your computer and use it in GitHub Desktop.
Save 4ndrej/75bb405418f451ca245e00095c6f8b4c to your computer and use it in GitHub Desktop.
A quick test to see if you have the JCE Unlimited Strength Jurisdiction Policy files installed. If you don't, in Java 6 you'll see 128. If you do, you'll see 2147483647. Thanks to http://stackoverflow.com/questions/11538746/check-for-jce-unlimited-strength-jurisdiction-policy-files
#!/bin/bash
javac Test.java
java Test
import javax.crypto.Cipher;
class Test {
public static void main(String[] args) {
try {
System.out.println("Hello World!");
int maxKeyLen = Cipher.getMaxAllowedKeyLength("AES");
System.out.println(maxKeyLen);
} catch (Exception e){
System.out.println("Sad world :(");
}
}
}
@4ndrej
Copy link
Author

4ndrej commented Oct 14, 2019

https://gist.github.com/evaryont/6786915#gistcomment-2987440

unzip -c ${JAVA_HOME}/jre/lib/security/local_policy.jar default_local.policy | grep -q javax.crypto.CryptoAllPermission && echo "unlimited JCE" || echo "vanilla JCE"

@4ndrej
Copy link
Author

4ndrej commented Oct 14, 2019

https://gist.github.com/evaryont/6786915#gistcomment-2249728

128 / 2147483647:

${JAVA_HOME}/bin/jrunscript -e "print (javax.crypto.Cipher.getMaxAllowedKeyLength('AES'))"

true / false:

${JAVA_HOME}/bin/jrunscript -e "print (javax.crypto.Cipher.getMaxAllowedKeyLength('AES') >= 256)"
${JAVA_HOME}/bin/jrunscript -e "print (javax.crypto.Cipher.getMaxAllowedKeyLength('RC5') >= 256)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment