Skip to content

Instantly share code, notes, and snippets.

@mmaia
Last active January 17, 2018 11:33
Show Gist options
  • Save mmaia/b1cc9c9fdf719fdfe2c7826afd5f182b to your computer and use it in GitHub Desktop.
Save mmaia/b1cc9c9fdf719fdfe2c7826afd5f182b to your computer and use it in GitHub Desktop.
Tests if java runtime has strong encryption packages installed

Due to legal reasons the default jdk from oracle does not have strong encryption enabled by default the Java Cryptography Extension (JCE) Unlimited Strength needs to be downloaded and configured.

The following java code can be used to test if your jvm has it configured:

import javax.crypto.Cipher;
import java.security.NoSuchAlgorithmException;

public class TestStrongEnc {
  public static void main(String[] args) {
    System.out.println("Do I have JCE unlimited java strong encryption extension installed? --->>>      " + TestStrongEnc.isUnlimitedKeyStrength());
  }

  public static boolean isUnlimitedKeyStrength()  {
    try {
      return Cipher.getMaxAllowedKeyLength("AES/GCM/NoPadding") == Integer.MAX_VALUE;
    } catch (NoSuchAlgorithmException nsae) {
      System.out.println("Your current in use jvm does NOT hava the JCE unlimited strengh ecnryption packages installed");
      return false;
    }
   }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment