Skip to content

Instantly share code, notes, and snippets.

@rch850
Forked from jehrhardt/KeyLengthDetector.java
Last active December 31, 2015 00:09
Show Gist options
  • Save rch850/7905848 to your computer and use it in GitHub Desktop.
Save rch850/7905848 to your computer and use it in GitHub Desktop.
import javax.crypto.Cipher;
import java.security.NoSuchAlgorithmException;
public class KeyLengthDetector {
public static void main(String[] args) {
String transformation = "AES";
if (args.length >= 1) transformation = args[0];
int allowedKeyLength = 0;
try {
allowedKeyLength = Cipher.getMaxAllowedKeyLength(transformation);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
System.out.println("The allowed key length for " + transformation + " is: " + allowedKeyLength);
Cipher.getInstance(transformation);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment