How to do PGP decryption in Java?

How to do PGP decryption in Java?
Photo by Xavier von Erlach / Unsplash

In my previous post, I mentioned how to encrypt data with PGP public key. In this post, I will tell you how to decrypt the data with PGP private key. You need a PGP key pair to test the encryption and decryption and see it works. Check this post to generate the PGP key pair.

Read|Load PGPPrivateKey from file

don't forget the deps before you write your code. Check the encrypt post for it.

Notes: The userId is the Real name + email address in format like:
`Real <Email>` , you were asked to provide these when you create the PGP key pair. Remember the password too.


Decrypt Data

BcPublicKeyDataDecryptorFactory (Bouncy Castle Library 1.64 API Specification)