Bouncy Castle in Application Jar
Hi,
I have an issue with packing the Bouncy Castle provider in a jar. I would like to include the Bouncy Castle Jar (bcprov-jdk15-138.jar) in my Main Application Jar. I use OneJar to pack the Bouncy Castle Jar, as well as a number of other Jars (i.e. Commons Collection, some of my own) in one Jar. All other Jars can be accessed but not the Bouncy Castle.
It is not a signing problem. If I copy the bcprov-jdk15-138.jar from my Jar to my JRE .../lib/ext/ it works fine, so the same Jar is fine if it lives in my ext folder.
The error I get is:
java.io.IOException: Error initialising store of key store: java.security.NoSuchProviderException: JCE cannot authenticate the provider BC
java.io.IOException: Error initialising store of key store: java.security.NoSuchProviderException: JCE cannot authenticate the provider BC
at org.bouncycastle.jce.provider.JDKKeyStore.makePBECipher(Unknown Source).
The line where it stops is the following:
if(type == CryptoUtils.UNLIMETED_ENCRYPTION){
try {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
FileOutputStream fos = new FileOutputStream(f);
KeyStore ks = KeyStore.getInstance("UBER", "BC");
ks.load(null, p.toCharArray());
ks.store(fos, p.toCharArray()); // It stops HERE
fos.close();
}catch (FileNotFoundException e){
System.out.println(e.toString());
e.printStackTrace();
}catch(IOException e){
System.out.println(e.toString());
e.printStackTrace();
}catch (KeyStoreException e) {
System.out.println(e.toString());
e.printStackTrace();
}catch (NoSuchProviderException e){
System.out.println(e.toString());
e.printStackTrace();
}catch (NoSuchAlgorithmException e){
System.out.println(e.toString());
e.printStackTrace();
}catch(CertificateException e){
System.out.println(e.toString());
e.printStackTrace();
}
}
My java security file looks like this:
#
# List of providers and their preference orders (see above):
#
security.provider.1=sun.security.provider.Sun
security.provider.2=sun.security.rsa.SunRsaSign
security.provider.3=com.sun.net.ssl.internal.ssl.Provider
security.provider.4=com.sun.crypto.provider.SunJCE
security.provider.5=sun.security.jgss.SunProvider
security.provider.6=com.sun.security.sasl.Provider
security.provider.7=org.bouncycastle.jce.provider.BouncyCastleProvider
Basically, is it so that the Jar for a security provider can not be outside of the ...../lib/ext/ directory? I think my CLASSPATH etc is OK since all other libs in my Jar can be accessed. This is on WindowsXP?
Is there anyone who has a good idea on how to distribute an application with Bouncy Castle. I really would like to avoid having everyone download and install the provider themself.
Thanks in advance.