MuleSoft Technical Guides

PGP Encryption and Decryption using MuleSoft

User MuleSoft Integration Team
Calendar February 12, 2021

Encryption is when information is converted into a secret code that hides information’s true meaning. Science of encrypting and decrypting information is called cryptography. In computing, unencrypted data is called plaintext, and encrypted data is called Ciphertext. Formulas used to encrypt, and decrypt are called encryption algorithms or Ciphers. Purpose of data encrypting is to protect the confidentiality of data shared across networks over the internet. API Integration security breaches can be minimized using the crypto module in Mule 4

Pretty Good Privacy (PGP) is an encryption system used for sending both encrypted files and emails. PGP shares some features with other encryption systems like Kerberos encryption (used to authenticate network users) and SSL encryption (used to secure websites).

We will be doing PGP encryption in MuleSoft using a PGP encrypt connector from Mule 4 crypto module.
First things first, generate new private and public key pairs using a tool named Kleopatra. Once the Kleopatra is installed, we can move on to the following steps.

1. Go to File > “New key Pair” and a dialogue box will open.

2. Enter the details, with Common-Name and email address fields as the required fields. In advanced settings, you can set the encryption algorithm. By default, it uses RSA and also you can select the key size whether it is 2048, 3082, 4096 bits. Note: We cannot use DSA for encryption since it is primarily used for digital signature and validation purposes

3. Add the passphrase for your key and click “OK” and a new key pair will be generated.

4. Once the key pair is created, you can export by clicking on the key and then “Export” and export the certificates to any location

5. Once you open the File, it should look like this.

6. Once the private and public key pair is exported, add the Crypto module from the exchange. Use Mule 4 PGP connector and set the config. Provide the file path for the public key for encryption in the PGP connector config and the fingerprint information. For decryption, provide a path for the private key.

7. Here is the snapshot of the application

8. We will be encrypting a json data and then decryption it again. Here is the sample input for:


9. After running and encrypting the data, the encrypted output looks like this:

Version: BCPG v1.61


10. Application logs look like this

PGP Encryption adds a security layer that makes sure that the data being transmitted via various channels is secured and can only be accessed by the person with the key that can decrypt the data. Using Mule 4 crypto module, a MuleSoft developer we can achieve different functionalities like PGP encryption-decryption, JCE encryption, calculating checksum and more.

Leave a comment

Your email address will not be published. Required fields are marked *