0

尝试使用最新的 camle 的 pgp 加密,但看到Caused by: java.lang.NoSuchMethodError: org.bouncycastle.openpgp.PGPPublicKeyRingCollection错误,我检查了类路径上的骆驼和充气城堡罐子的正确版本,还尝试了最新的 1.59 bc 版本。- 我错过了什么吗?

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)

测试路线:

  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");
        }
    }

编辑:还检查了运行时这些 jar 是否在类路径中::~/.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:

所以事实证明 jdk 版本不是问题,但问题是当我们在 java 安装$JAVA_HOME/jre/lib/ext目录中重命名较旧的 bc jar 时,.out我们假设这些 jar 没有被加载到类路径上,但似乎它们确实被加载了。当我从 中完全删除这些旧 jar 时 $JAVA_HOME/jre/lib/ext,一切都适用于 java 8 版本 121 和 172。

4

0 回答 0