Thinking of it, the OpenPGP.js library is quite an amazing feat.
Although intimidating at first (and slightly under-documented, IMHO) OpenPGP.js provides one of the easiest and most reliable ways to perform PGP encryption on the front side. Let’s see how!
Quick reminder: this tutorial’s previous posts are available here:
- Java keys generation
- Java PGP encryption
- Front end PGP encryption with OpenPGP.js
Generate key pairs
OpenPGP can very easily generate key pairs, including ECC keys since version 3. We shall stick to RSA keys for this tutorial, though.
So, having imported the openpgp library we can now obtain our RSA key pairs as follows:
Make sure you choose a good passphrase, and also use the same number of bits than the Java RSA keys.
Front end PGP encryption and decryption
We know we need Mr Java’s public key to encrypt the message.
One we have all the required elements, we proceed on encrypting the message addressed to Mr Java:
And that’s basically all there is to it.
Running the tutorial code
For simplicity, I have set up a Spring Boot web application. Just run the Application class and point your browser to http://localhost:8080 . A simple index HTML page will give you links to run the test code we discussed here.
Don’t worry though: the hardest part is behind us now.
Until next time,