1. Generate pgp keys
2. Create a maven project and add below dependencies
<camel.version>2.13.2</camel.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-ftp</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-crypto</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>bouncycastle</groupId>
<artifactId>bcpg-jdk13</artifactId>
<version>121</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
3. Create a Camel Route to start encryption
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.converter.crypto.PGPDataFormat;
import org.apache.camel.main.Main;
public class EncryptionTest {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Main main = new Main();
main.enableHangupSupport();
main.addRouteBuilder(new MyRouteBuilder());
main.run(args);
}
}
class MyRouteBuilder extends RouteBuilder {
@Override
public void configure() {
try {
System.out.println("My Encryption/Decryption route started");
// Encryption
PGPDataFormat encrypt = new PGPDataFormat();
encrypt.setKeyFileName("vinodpublickeyfile.pgp");
encrypt.setKeyUserid("vinod");
from("file:tobeencrypt?noop=true;delete=true").marshal(encrypt).to("file:encrypted");
// Decryption
PGPDataFormat decrypt = new PGPDataFormat();
decrypt.setKeyFileName("vinodprivatekeyfile.pgp");
decrypt.setPassword("vinod@123");
from("file:tobedecrypt").unmarshal(decrypt).to("file:decrypted");
} catch (Exception e) {
e.printStackTrace();
}
}
}
After running the above main program camel route will start and we can see the two directories are created and we can place the files which we needs to be encrypted.



