Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if Unlimited Cryptography is available

Tags:

java

jce

How can I check, in Java code, if the current JVM have unlimited strength cryptography available?

like image 302
Chi-Lan Avatar asked Oct 31 '11 12:10

Chi-Lan


People also ask

Is JCE included in JDK?

Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files Download. The Java Cryptography Extension enables applications to use stronger versions of standard algorithms. Current versions of the JDK do not require these policy files. They are provided here for use with older version of the JDK.

What is unlimited strength jurisdiction policy files?

JCE Unlimited Strength Policy FilesIt is defined by the difficulty of discovering the key, which depends on the used cipher and length of the key. In general, a longer key provides stronger encryption. The limited cryptographic strength uses a maximum 128-bit key.


2 Answers

In the same spirit as the answer of Dan Cruz, but with a single line of code and without going trough exceptions:

boolean limit = Cipher.getMaxAllowedKeyLength("RC5")<256; 

So a complete program might be:

import javax.crypto.Cipher;  public class TestUCE {   public static void main(String args[]) throws Exception {     boolean unlimited =       Cipher.getMaxAllowedKeyLength("RC5") >= 256;     System.out.println("Unlimited cryptography enabled: " + unlimited);   } } 
like image 129
KonstantinSpirov Avatar answered Sep 30 '22 14:09

KonstantinSpirov


If you are on Linux and you have installed the JDK (but Beanshell is not available), you can check with the runscript command provided with the JDK.

jrunscript -e 'exit (javax.crypto.Cipher.getMaxAllowedKeyLength("RC5") >= 256 ? 0 : 1);'; echo $? 

This returns a 0 status code if the Unlimited Cryptography is available, or 1 if not available. Zero is the correct 'success' return value for shell functions, and non-zero indicates a failure.

like image 30
Igor Metz Avatar answered Sep 30 '22 13:09

Igor Metz