PGP Encryption and Decryption using MuleSoft

Published on
February 12, 2021
Author
MuleSoft Integration Team
PGP Encryption and Decryption using MuleSoft

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… Continue reading PGP Encryption and Decryption using MuleSoft

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:

 { "firstName":"John", "lastName":"Doe", "dateOfBirth":"28/05/1994", "employmentHistory":{ "companyName":"Amazon", "location":"Hyderabad" } } 

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

 -----BEGIN PGP MESSAGE----- Version: BCPG v1.61 hQEMA8pVfKM99DLIAQgAwf7sFW/fTt0sBbJ0COiqxswiJ9F1v1G3RelBBBCGshYt YdS+l5chfm4gQd176u5u7kVqS/+GSn13fgfHJNnaSfqEmvEA99YdwsX0ucSgTrE7 Pklq3wCf0WlOY6qpk+rh+/754nysG672yXizYQNelgVbCjtf07rEH5jMkJqTj456 7sHzETA8nKhwLF10HDSGdrA8s/+gITeCj02UV3XNW4g+wAfSdJOsa8hFThZWiajY OyZbK2rUWzzBaE0kj3dddbMBuD+zFfkxo+f+NiyeeZOAP1alps0PTmvApvKb1KV9 kkADWJ1NeE3WqGa6syII3kSRCX/40rHmGxHGN6UO3tK3ATm+KOGM/Pi+gTkWWNs5 0LHmJFw0RTvsAVWNqB6z8GD2fCen94GA1ijNd2jP7olZEMzQMbYJZ1DpdKl9IF7X 48IWg89yD+JSJjrkxbr1WAq/6RooApo2blhOeeY5lS2K33SX8Hm8UkjqyvFEUjaF ACPLliGyLRW6aHTkuzNlWZg9zFy1X89NR9+/gDwyeJH6VK+4L3Z+hse6XP9m5QuG jdCIaIlX9LUiGcvnPeuNNHwlM7Y2qOga =vY2Y -----END PGP MESSAGE----- 

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.

Recent Blogs

Connecting MuleSoft and Azure SQL with Entra ID
BlogJul 14, 2025

Connecting MuleSoft and Azure SQL with Entra ID

Introduction Establishing a secure connection between MuleSoft and Azure SQL Database can be challenging, especially if you are using Entra ID (formerly known as Azure Active Directory) for authentication. This blog walks through a fully working configuration for connecting to Azure SQL using ActiveDirectoryServicePrincipal in Mule runtime 4.7.4 with Java 8 — addressing driver setup,… Continue reading Connecting MuleSoft and Azure SQL with Entra ID

Read More
Blog
2 min read

Connecting MuleSoft and Azure SQL with Entra ID

Introduction Establishing a secure connection between MuleSoft and Azure SQL Database can be challenging, especially if you are using Entra ID (formerly known as Azure Active Directory) for authentication. This blog walks through a fully working configuration for connecting to Azure SQL using ActiveDirectoryServicePrincipal in Mule runtime 4.7.4 with Java 8 — addressing driver setup,… Continue reading Connecting MuleSoft and Azure SQL with Entra ID

Read More
Understanding Salesforce Flow Approval Processes
BlogJun 30, 2025

Understanding Salesforce Flow Approval Processes

Introduction: Salesforce introduced Flow Approval Processes in the Spring '25 release. This is an evolved version of the classic approval process model, powered by Flow Orchestrator. The new approach brings unprecedented flexibility, enabling the creation of dynamic, multi-level, and logic-driven approval workflows that are entirely declarative. Continue reading the blog to get a deeper understanding… Continue reading Understanding Salesforce Flow Approval Processes

Read More
Blog
5 min read

Understanding Salesforce Flow Approval Processes

Introduction: Salesforce introduced Flow Approval Processes in the Spring '25 release. This is an evolved version of the classic approval process model, powered by Flow Orchestrator. The new approach brings unprecedented flexibility, enabling the creation of dynamic, multi-level, and logic-driven approval workflows that are entirely declarative. Continue reading the blog to get a deeper understanding… Continue reading Understanding Salesforce Flow Approval Processes

Read More
Capturing Real-time Record Updation Using LWC
BlogMay 14, 2025

Capturing Real-time Record Updation Using LWC

Introduction In modern CRM ecosystems, real-time Salesforce integration and seamless user experiences are no longer optional but fundamental for driving operational efficiency. Imagine your sales reps making important Opportunity changes, but the ERP remains out of sync, leading to confusion and data errors. We understood the necessity to bridge this data gap and implemented a… Continue reading Capturing Real-time Record Updation Using LWC

Read More
Blog
5 min read

Capturing Real-time Record Updation Using LWC

Introduction In modern CRM ecosystems, real-time Salesforce integration and seamless user experiences are no longer optional but fundamental for driving operational efficiency. Imagine your sales reps making important Opportunity changes, but the ERP remains out of sync, leading to confusion and data errors. We understood the necessity to bridge this data gap and implemented a… Continue reading Capturing Real-time Record Updation Using LWC

Read More
All About Schedulers: Mule 4
BlogMay 7, 2025

All About Schedulers: Mule 4

In the world of Mule 4, automating repetitive tasks and triggering flows at defined intervals is necessary for building efficient and robust integration solutions. This is where Mule 4 schedulers come into use. This blog post explores the intricacies of scheduling in Mule 4, providing practical examples and best practices to help you get deeper… Continue reading All About Schedulers: Mule 4

Read More
Blog
7 min read

All About Schedulers: Mule 4

In the world of Mule 4, automating repetitive tasks and triggering flows at defined intervals is necessary for building efficient and robust integration solutions. This is where Mule 4 schedulers come into use. This blog post explores the intricacies of scheduling in Mule 4, providing practical examples and best practices to help you get deeper… Continue reading All About Schedulers: Mule 4

Read More