使用 Apache Camel 进行 PGP 加密 [英] PGP Encryption with Apache Camel

查看:28
本文介绍了使用 Apache Camel 进行 PGP 加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PGP 加密/解密方法和 Apache Camel 加密和解密文件.

I am trying to encrypt and decrypt a file using PGP Encryption/Decryption methodology with Apache Camel.

此外,我还安装了 Kleopatra 来生成私钥和公钥.使用 Kleopatra 我已经成功生成了我的密钥.密钥和公钥在.asc"扩展名中.

Further I have installed Kleopatra to generate the private and public keys. Using Kleopatra i have generated my keys successfully. The secret key and public keys are in ".asc" extension.

下面是我用来加密文件的一段代码

Below is the piece of code i am using to encrypt the file

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class PGPENC {
    public static void main(String[] args) throws Exception {
        CamelContext camelContext = new DefaultCamelContext();

        camelContext.addRoutes(new RouteBuilder() {
            public void configure() throws Exception {

                String publicKeyFileName = "file:C:\\Users\\karthick\\Desktop\\PGP\\PGP\\Public_Key.asc";
                String keyUserid = "Karthick Sambanghi <karthick88it@gmail.com>";

                from("file:C:\\Users\\ITSS\\karthick\\PGP\\PGP\\IN?noop=true;delete=true").marshal()
                        .pgp(publicKeyFileName, keyUserid).to("file:C:\\Users\\ITSS\\Desktop\\PGP\\PGP\\OUT");

            }
        });

        camelContext.start();

        Thread.sleep(5000);
        camelContext.stop();
    }
}

这里程序成功执行,没有任何错误,但文件没有在 OUT 文件夹中加密.无论如何要检查camelContext"返回语句是成功还是失败?

Here the program executed successfully without any errors but the file is not being encrypted in OUT folder. Is there anyway to check the "camelContext" return statement whether it is success or failure ?

以下是当前用于执行程序的库

Below are the libraries used currently for executing the program

bcpg-jdk15on-1.52
bcprov-ext-jdk15on-1.57
camel-context-2.22.1
camel-core-2.22.1
camel-crypto-2.19.1
slf4j-api-1.7.25
slf4j-nop-1.7.25

推荐答案

您可以通过在程序中添加 org.apache.log4j.BasicConfigurator.configure() 来启用控制台中的骆驼日志记录.

you can enable camel logging in the console using by adding in your programm org.apache.log4j.BasicConfigurator.configure().

使用它您可以验证路由是否启动并消耗了文件.所以通过添加一些日志来执行你的程序:

Using that you could verify if the route started and consumed the file. so Executing your programm with adding some logs :

 CamelContext camelContext = new DefaultCamelContext();
    BasicConfigurator.configure();
    camelContext.addRoutes(new RouteBuilder() {

      public void configure() throws Exception {

        String publicKeyFileName = "file:C:\\LocalData\\Keys\\pgp_public.asc";
        String keyUserid = " ";

        from("file:C:\\Test\\Test\\IN")
            .log("file received")
            .marshal().pgp(publicKeyFileName, keyUserid)
        .to("file:C\\Test\\Test\\OUT");

      }
    });
    camelContext.start();
    Thread.sleep(30000);
    camelContext.stop();
  } 

我可以注意到路由正在启动,从 in 文件夹中使用文件,然后失败,但有例外:

I can notice that the route is starting, consuming files from the in folder and fails then with the exception :

Caused by: java.lang.NoSuchMethodError: org.bouncycastle.openpgp.PGPPublicKeyRingCollection.<init>(Ljava/io/InputStream;)V
    at org.apache.camel.converter.crypto.PGPDataFormatUtil.findPublicKey(PGPDataFormatUtil.java:64)
    at org.apache.camel.converter.crypto.PGPDataFormatUtil.findPublicKey(PGPDataFormatUtil.java:54)
    at org.apache.camel.converter.crypto.PGPDataFormat.marshal(PGPDataFormat.java:64)
    at org.apache.camel.processor.MarshalProcessor.process(MarshalProcessor.java:59)
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)

这是 Camel 文档中的一个错误,请在此处找到详细信息:https://jira.apache.org/jira/browse/CAMEL-12574

This is a bug in Camel documentation, please find here details: https://jira.apache.org/jira/browse/CAMEL-12574

这篇关于使用 Apache Camel 进行 PGP 加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆