Java Cryptography Extension – Check Maximum Allowed Key Size

In Java, there is a limitation on key size by the JCE Jurisdiction Policy. If you manipulate a private key with bit size which is larger than the limitation, it will throw a InvalidKeyException complaining about Illegal key size.

The following piece of Java code will check maximum key size of all the algorithms and print the result to the console.

import java.util.Set;
import javax.crypto.Cipher;

public class CheckKeySize {
	public static void main(String[] args) {
		try {
			Set<String> algorithms = Security.getAlgorithms("Cipher");
			for(String algorithm: algorithms) {
			    int max;
				max = Cipher.getMaxAllowedKeyLength(algorithm);
			    System.out.printf("%-22s: %dbit%n", algorithm, max);
		} catch (NoSuchAlgorithmException e) {


Console output

BLOWFISH              : 128bit
ARCFOUR               : 128bit
PBEWITHMD5ANDDES      : 128bit
RC2                   : 128bit
RSA                   : 2147483647bit
DESEDE                : 2147483647bit
AESWRAP               : 128bit
AES                   : 128bit
DES                   : 64bit
DESEDEWRAP            : 128bit
RSA/ECB/PKCS1PADDING  : 2147483647bit
PBEWITHSHA1ANDRC2_40  : 128bit


Done =)

Reference: セキュリティ

7 thoughts on “Java Cryptography Extension – Check Maximum Allowed Key Size”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.