Domanda

I have two applets. One does:

RSAPrivateKey sKey = getPrivateKey(keyFile);
Cipher cipher = Cipher.getInstance("RSA/None/OAEPWithSHA512AndMGF1Padding");
cipher.init(Cipher.DECRYPT_MODE, sKey);

sKey is 2048 bits long.

the other one:

byte[] kSession= fileToBytes(kSessionFile);
SecretKeySpec skeySpec = new SecretKeySpec(kSession, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

kSession is 32 Bytes long

I am aware of the need to install extended JCE Unlimited Strength Jurisdiction Policy files for some cryptographic operations, as noted here.

My question is, when these jars are not installed, why does encryption throw the same exception while decryption does not?

È stato utile?

Soluzione

The key type, size and platform (the JRE or JDK version) are all required knowledge to see if you require the unlimited crypto files. These files depend on a policy set by Oracle to comply with specific import regulations. Some ciphers + key sizes are free for use and others are not. Which ones are allowed and which ones are not depends on politics rather than technical reasoning.

It does not matter if you are using encryption or decryption. Decryption can be used for encryption in certain modes of encryption, such as CTR mode encryption.


In your particular case an RSA key of 2048 bits has a lot less strenght than an AES key of 256 bits. So it is not so strange that one part of your code throws an exception and the other part doesn't. The use of AES keys of 192 or 256 bits is precluded unless you have the unlimited strength files for Java(TM) SE Runtime Environment (build 1.7.0_45-b18).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top