Unknown KeySpec type ElGamalPrivateKeySpec

Some customers that have deployed DidiSoft OpenPGP Library for Java as part of a web application, have noticed that the exception below is thrown when they perform a hot deploy on the application server:

org.bouncycastle.openpgp.PGPException: Exception constructing key
   at org.bouncycastle.openpgp.PGPSecretKey.extractPrivateKey(Unknown Source)
   at org.bouncycastle.openpgp.PGPSecretKey.extractPrivateKey(Unknown Source)

Caused by: java.security.spec.InvalidKeySpecException: Unknown KeySpec type: org.bouncycastle.jce.spec.ElGamalPrivateKeySpec
   at org.bouncycastle.jce.provider.JDKKeyFactory.engineGeneratePrivate(Unknown Source)
   at org.bouncycastle.jce.provider.JDKKeyFactory$ElGamal.engineGeneratePrivate(Unknown Source)


The reason
for the above exceptions is that the library JAR files are bundled with the web application. Hence after an application is stopped/started, they are loaded in another class loader, while the BouncyCastle security provider is already registered with a class loader that is now unavailable (has been destroyed after the web application has stopped).

The solution to this situation is to ship the application without the library JAR files.
They must be placed in a folder shared for all applications running on the Application server.

Below are listed the shared folders for some application servers.

Tomcat 5.x
<tomcat folder>/shared/lib/

Tomcat 6.x
$CATALINA_BASE/lib/

Web Sphere
<was folder>/lib

WebLogic
<weblogic folder>/common/lib