Checking if Unlimited Cryptography is available

Chi-Lan picture Chi-Lan · Oct 31, 2011 · Viewed 32.4k times · Source

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

Answer

KonstantinSpirov picture KonstantinSpirov · Dec 22, 2011

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);
  }
}