Anibaru
Anibaru

Reputation: 193

Installing JCE on Ubuntu Server 10.04 with JDK 6

I've been working with cryptography and have some problems. I always get this exception.

java.io.IOException: exception decrypting data - java.security.InvalidKeyException: Illegal key size at org.bouncycastle.jce.provider.JDKPKCS12KeyStore.cryptData(Unknown Source) at org.bouncycastle.jce.provider.JDKPKCS12KeyStore.engineLoad(Unknown Source)

Searching google one finds that a JCE Unlimited Policy File is needed. As you download it, the instalation instructions say that the only thing needed to do is to copy both jar files included into /security/ folder of your JRE. Well that doesn´t work, i've searched all the directories of my machine to find any other java installation, and i found none. I double checked that the files were correct

Some info:

java -version reports:
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)

I've installed this Java version using apt-get install sun-java6

Any ideas on this?

Upvotes: 0

Views: 1000

Answers (1)

Anibaru
Anibaru

Reputation: 193

The solution to my problems came from other place and i'll explain here. Before the error i had:

KeyStore ks = KeyStore.getInstance("pkcs12","BC");  
File cert = new File(certPath);     
FileInputStream fis = new FileInputStream(cert);        
ks.load(fis,certpassword.toCharArray());

And now i have:

KeyStore.Builder builder = null;
ProtectionParameter paramet = new PasswordProtection(certpassword.toCharArray());
builder = KeyStore.Builder.newInstance("PKCS12", null, new File(certPath), paramet);
KeyStore ks = builder.getKeyStore();
File cert = new File(certPath);
FileInputStream fis = new FileInputStream(cert);        
ks.load(fis, certpassword.toCharArray());

This code is probably not completely correct but it works. As for a reason to this i don´t have a clue. I just tried a different way of loading the certificate and this one worked.

I haven´t tested if this solution works without the unlimited policy files.

Upvotes: 0

Related Questions