0

Trying to use latest camle's pgp encryption, but seeing Caused by: java.lang.NoSuchMethodError: org.bouncycastle.openpgp.PGPPublicKeyRingCollection error, I have checked I have correct versions of camel and bouncy castle jars on classpath, also tried with latest 1.59 bc version. - am I missing anything?

mvn dependency:tree|egrep 'bcp|crypto'
[INFO] +- org.apache.camel:camel-crypto:jar:2.21.0:compile
[INFO] |  +- org.bouncycastle:bcpg-jdk15on:jar:1.57:compile
[INFO] |  +- org.bouncycastle:bcprov-jdk15on:jar:1.57:compile
[INFO] |  +- org.apache.camel:camel-crypto:jar:2.21.0:compile
[INFO] |  |  +- org.bouncycastle:bcpg-jdk15on:jar:1.57:compile
[INFO] |  |  +- org.bouncycastle:bcprov-jdk15on:jar:1.57:compile

Caused by: java.lang.NoSuchMethodError: org.bouncycastle.openpgp.PGPPublicKeyRingCollection.<init>(Ljava/io/InputStream;Lorg/bouncycastle/openpgp/operator/KeyFingerPrintCalculator;)V
    at org.apache.camel.converter.crypto.PGPDataFormatUtil.findPublicKeys(PGPDataFormatUtil.java:204)
    at org.apache.camel.converter.crypto.PGPDataFormatUtil.findPublicKeys(PGPDataFormatUtil.java:96)
    at org.apache.camel.converter.crypto.PGPDataFormat.getEncryptionKeys(PGPDataFormat.java:235)
    at org.apache.camel.converter.crypto.PGPKeyAccessDataFormat.marshal(PGPKeyAccessDataFormat.java:222)
    at org.apache.camel.processor.MarshalProcessor.process(MarshalProcessor.java:69)

Test Route:

  class DeadLetterChannelRoute1 extends RouteBuilder {

        @Override
        public void configure() throws Exception {
            from("file:source/inbox")
                    //.errorHandler(deadLetterChannel("file:source/dlc1").useOriginalMessage())
                    .process(exchange -> System.out.println( "1 >>> BEFORE:\n " + exchange.getIn().getBody(String.class)))
                    .marshal().pgp(encryptKeyFileName,encryptKeyUserid)
                    .process(exchange -> System.out.println( "1 >>> AFTER: \n" +  exchange.getIn().getBody(String.class)))
                    .to("file:source/pgp_inbox");
        }
    }

EDIT: Also checked that on runtime these jars are in classpath: :~/.m2/repository/org/bouncycastle/bcpg-jdk15on/1.57/bcpg-jdk15on-1.57.jar:~/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.57/bcprov-jdk15on-1.57.jar:

So it turned out that jdk version wasn't a problem, but issue was when we renamed the older bc jars in java installation $JAVA_HOME/jre/lib/ext dir with .out we assumed these jars are not being loaded on classpath, but it seems they do get loaded. When I deleted these older jar completely from $JAVA_HOME/jre/lib/ext, everything works with both java 8 versions 121 and 172.

Ronak Patel
  • 3,819
  • 1
  • 16
  • 29

0 Answers0