Bouncy castle no such method error

2020-04-13 20:28发布

问题:

I'm trying to decrypt a file using Bouncy Castle v1.53 PGP and Using PGPUtil class. The program works fine in my Eclipse, but given following error when integrated inside a war file and deployed onto a weblogic server.I'm using following dependencies: 1)bcpg-jdk15on 2)bcprov-jdk15on

Error

java.lang.NoSuchMethodError:   
 org.bouncycastle.util.Strings.newList()Lorg/bouncycastle/util/StringList;
 at org.bouncycastle.bcpg.ArmoredInputStream.<init>(Unknown Source)
 at org.bouncycastle.bcpg.ArmoredInputStream.<init>(Unknown Source)
 at org.bouncycastle.openpgp.PGPUtil.getDecoderStream(Unknown Source)`

Resolution

This problem is resolved when I copied following classes into my source folder:

org.bouncycastle.util.Strings  
org.bouncycastle.util.StringList  
org.bouncycastle.bcpg.ArmoredInputStream  
org.bouncycastle.openpgp.PGPUtil`

by changing their Class Names

However, I want a better fix than this as I feel this is some Jar Conflict Please let me know if anyone finds one

回答1:

That error is likely happening because you are using one version of the bouncycastle .jars when you run with Eclipse, but there is a different version of one of those .jars which is on the classpath that Weblogic is using when running your application.

You will need to investigate how exactly Weblogic sets up the classpath, and make sure the version of the .jars you need are on the classpath before the preexisting version (unless that preexisting version is there by mistake, in which case you can just remove the preexisting one from the classpath).