Saturday, September 8, 2018

PGP Encryption using Apache Camel

PGP (Pretty Good Privacy) Encryption is a widely used encryption mechanism which can be used to provide public key encryption.
There are many PGP encryption implementations using Java language which are quite complex. But Apache Camel Crypto component facilitates a very simple and convenient way of implementing PGP encryption.
Following code encrypts a given message using Apache Camel. org.apache.camel:camel-crypto is the only one library i have used here.
Most of the example in the internet shows the way which a file is used as the input for the encryption. But here i will show you how to directly encrypt a string (text message).
I'm using the public key in the public.gpg file to encrypt the message. The code is really straight foreword. Complete working project is available on GitHub and the URL is available at the bottom. All required key files are available there. You can clone the project and execute the program.

Following is the GitHub URL of complete project of this tutorial.
https://github.com/lakjcomspace/PGPEncryption