Detecting key length restrictions

Is there an easy way to determine programatically if a user has the basic JDK 1.4 JCE implementation or has installed the unlimited strength version? Basically, I want to present a user with a means of setting the key length, but I need to know what the max is.
[269 byte] By [rgeimera] at [2007-9-19]
# 1

Let me be a little more specific. I'm presenting the user with a GUI widget (JSlider, JTextField, whatever) that will allow them to enter the desired keysize. After they enter the keysize, they hit an 'Encrypt" button and the program goes off and does something like the following:

int keysize = keySizeWidget.getValue()

KeyGenerator kg = KeyGenerator.getInstance("Blowfish");

kg.init(keysize );

SecretKey sk = kg.generateKey();

Cipher c = Cipher.getInstance("Blowfish");

c.init(Cipher.ENCRYPT_MODE,sk);

Now, if the user selects a keysize of 448, but only has the default JRE 1.4 policy files (i.e. they haven't downloaded the unlimited versions), then I get a SecurityException at the call to c.init() reporting an unsupported keysize. However, a long time passes before the exception is thrown, and the user has no feedback when they provide the keysize that the value will be rejected later when they hit the encrypt button.

Is there any means of finding out ahead of time what keysizes a given Cipher object will accept? It would be nice to setup the interface so that they can only select valid keysizes (i.e set the maximum value of a JSlider to 128 if they don't have the unlimited encription support).

Any help would be appreciated.

rgeimera at 2007-7-8 > top of java,Security,Cryptography...
# 2
There is no easy way. But you can try to generate test keys with different length in the application init time and then use that information in your GUI.
euxxa at 2007-7-8 > top of java,Security,Cryptography...
# 3
Yeah, that's what I was hoping to avoid. Oh well, have a duke anyway :-).
rgeimera at 2007-7-8 > top of java,Security,Cryptography...
# 4
Any other replies? I'm dyin' here!
rgeimera at 2007-7-8 > top of java,Security,Cryptography...
# 5

Well, it's me again. :-)

Unfortunately Sun's JCE implementation seems keeps crypto policy separate from the system policy and it is impossible to retrieve it by using security classes. The only way I did find to workarrount this problem is to parse policies by hands. There is classes in Sun's JCE 1.2 which can be used for this, but practically they are obfuscated and their names are not CryptoPermission and CryptoAllPermission.

So, you should read /jre/lib/security/local_policy.jar, find and parse the default_local.policy file inside that jar and check if CryptoPermission entries has any limitations; or simplier if there is CryptoAllPermissions then there is no limitations.

euxxa at 2007-7-8 > top of java,Security,Cryptography...
# 6

Thanks again! I'll give you two more dukes, leaving two available in case anyone else has any other ideas about how to do this.

Sun, are you listening? We need an easy way to query for encryption restrictions, at least until the U.S. government wakes up and realizes that it is pointless to try to regulate this stuff.

rgeimera at 2007-7-8 > top of java,Security,Cryptography...
# 7
Ok, last chance for dukes on this topic. If I don't receive any other ideas, I will reward the remaining dukes to the previous poster.
rgeimera at 2007-7-8 > top of java,Security,Cryptography...