Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Providers load order conflict (ExceptionInInitializerError)

843811May 19 2006 — edited May 19 2006
Hello, I have a problem when using several java.security.Provider (BouncyCastleProvider and SunJCE), by the sight, the order in which they are loaded is the problem.

If load BouncyCastleProvider at position 1, and SunJCE in the 2, (following code) is throwed java.lang.ExceptionInInitializerError
java.security.Security.insertProviderAt(new org.bouncycastle.jce.provider.BouncyCastleProvider(), 1);
java.security.Security.insertProviderAt(new com.sun.crypto.provider.SunJCE(), 2);
SecretKeyFactory kf = SecretKeyFactory.getInstance("PBEWithMDAndDES"); // throws ExceptionInInitializerError
If the position are another (SunJCE at 1, and BouncyCastle 2)
java.security.Security.insertProviderAt(new com.sun.crypto.provider.SunJCE(), 1);
java.security.Security.insertProviderAt(new org.bouncycastle.jce.provider.BouncyCastleProvider(), 2);
SecretKeyFactory kf = SecretKeyFactory.getInstance("PBEWithMDAndDES"); // it works well!
yes works well (need that BouncyCastle exist at position 1), but I have problems soon, with my jar library that uses BouncyCastleProvider (which I cannot modify).

I have tried to do the following:
java.security.Security.insertProviderAt(new org.bouncycastle.jce.provider.BouncyCastleProvider(), 1);
java.security.Security.insertProviderAt(new com.sun.crypto.provider.SunJCE(), 2);

Provider sunJCEProv = java.security.Security.getProvider("SunJCE");

SecretKeyFactory kf = SecretKeyFactory.getInstance("PBEWithMDAndDES", sunJCEProv); // does not work either (ExceptionInInitializerError)
here I am indicating him the Provider (SunJCE), but seems to take in any case bouncycastle (the Provider in the position 1).

The full stackTrace of the exception is:
java.lang.ExceptionInInitializerError 
	AT javax.crypto.SecretKeyFactory.getInstance(DashoA12275)
	...

Caused by: java.lang.SecurityException: 
	Cannot for Seth up certs trusted CAs AT javax.crypto.SunJCE_b. (DashoA12275)
... 25 and more
Caused: java.security.PrivilegedActionException: java.security.InvalidKeyException: Public for key 		presented not 			certificate signature AT java.security.AccessController.doPrivileged(Native Method)
	... 26 and more
Caused by: java.security.InvalidKeyException: Public for key presented not certificate signature 
	AT org.bouncycastle.jce.provider.X509CertificateObject.checkSignature(Unknown Source) 
	AT org.bouncycastle.jce.provider.X509CertificateObject.verify(Unknown Source) 
	AT javax.crypto.SunJCE_b.c(DashoA12275)
	AT javax.crypto.SunJCE_b.b(DashoA12275) 
	AT javax.crypto.SunJCE_q.run(DashoA12275)
Some idea?
Thanks to all!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 16 2006
Added on May 19 2006
3 comments
822 views