0

I am trying to PGP Encrypt a file using Java code. I have generated pgp keys (.asc file) for the same. Below is my Java code:

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

public class PGPEncryption {
    public static void main(String[] args) throws Exception {
        String publicKeyFileName="abc-pub-sub.asc";
        String keyUserid="abc";
        String input_file_path="test.csv";
        String output_file_path="/tmp/output";
        camelContext.addRoutes(new RouteBuilder() {
            public void configure() throws Exception {
                from(input_file_path).marshal()
                .pgp(publicKeyFileName, keyUserid).to(output_file_path);
            }
        });
        camelContext.start();
        Thread.sleep(5000);
        camelContext.stop();
    }
}

Below are the Jars I added in my build Path :

bcpg-jdk15on-1.56.jar
bcprov-jdk15on-1.56.jar
camel-core-2.6.0.jar
camel-crypto-2.9.5.jar
commons-logging-1.2.jar
slf4j-api-1.7.25.jar
slf4j-nop-1.7.25.jar

But above code is giving me compile time error as below :

"The method pgp(String, String) is undefined for the type DataFormatClause<ProcessorDefinition<RouteDefinition>>"

Could someone please help me in fixing this ?

Also I tried to export my code as Runnable Jar with compile time errors. But after I execute my Jar file I am facing below error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/fusesource/commons/management/ManagementStrategy

I am not sure if I am missing any basic thing here. Could someone please help here? Thanks in Advance.

Referred Link : PGP Encryption with Apache Camel

user2531569
  • 609
  • 4
  • 18
  • 36
  • Try to create a maven project, with dependencies provided from https://mvnrepository.com/artifact/org.apache.camel/camel-cor. You can see that the required import lines are only import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; . I test your code and I can compile it. – Mihai8 Oct 01 '19 at 23:45
  • Ok. Let me try. Thanks for your response – user2531569 Oct 02 '19 at 00:21

0 Answers0