骆驼2.21.0 - pgp加密无法正常工作

时间:2018-05-30 18:04:20

标签: encryption apache-camel pgp openpgp spring-camel

尝试使用最新的camle pgp加密,但看到Caused by: java.lang.NoSuchMethodError: org.bouncycastle.openpgp.PGPPublicKeyRingCollection错误,我已经检查过我在classpath上有正确版本的camel和bouncy castle jar,也尝试过最新的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目录中使用.out重命名旧的bc jar时我们假设这些jar没有加载到classpath上,但似乎它们确实被加载了。当我从$JAVA_HOME/jre/lib/ext完全删除这些旧jar时,一切都适用于java 8版本121和172.

0 个答案:

没有答案