Sunday, May 31, 2020

PGP encryption/decryption using Apache Camel, Spring Boot

First, an update on the computing environment. The Acer C720 i3 core with 4G RAM Chromebook was updated with a 128 GB SSD hard drive and converted to Ubuntu 18.04, most recently to Lubuntu 20.04. It's working great using the xcfe desktop I was used to using with Crouton.

So, I've got a requirement to convert a bunch of files downloaded from an SFTP server encrypted with PGP. There's plenty of resources online to see how to do generate a public-private key pair. Export the public key to an *.asc file, and make a copy of the private key, also in *.asc. These will both by armored, meaning Base64 encoded.

Copy the keys to the project root of your Spring Boot application, e.g. in a /keys directory.

From the documentation at PGP - Apache Camel, add the following dependency to build.gradle,

compile group: 'org.apache.camel.springboot', name: 'camel-crypto-starter', version:camelCoreVersion 

Now, we're ready to add some code. I've uploaded the code to a GitHub gist.

Create folders for /pgp/original, /pgp/encrypted, and
/pgp/decrypted. Create a file in /pgp/original with some secret text. Run PGPEncryptor, and you should see output in the encrypted and decrypted folders with your encrypted file, and decrypted file respectively.

Well, it's Sunday and this POC needed to be complete for Monday, just in time!

Much help was obtained from this blog post and other resources found around the web. Many thanks to the authors!