PGP Encryption and Decryption in Mule 4

Pankaj Badi
4 min readFeb 13, 2022

Introduction:

Cryptography is the study of secure communications techniques that allow only the sender and intended recipient of a message to view its contents.

What is Private and Public Keys:

  1. The public key is only used to encrypt data and to decrypt the data, the private key is used and is shared.
  2. Private Key is used to both encrypt and decrypt the data and is shared between the sender and receiver of encrypted data.

PGP Cryptography:

The e-mail message is hashed by using a hashing function to create a digest.The digest is then encrypted to form a signed digest by using the sender’s private key, and then signed digest is added to the original email message.The original message and signed digest are encrypted by using a one-time secret key created by the sender.The secret key is encrypted by using a receiver’s public key.

MuleSoft:

  1. In the Mule Pallete you can not able to find the cryptography module.So,serach this module from search exchange add your account of your anypoint platform.

2. Now generate the keys from git bash

3. Take following commands on git bash:

gpg — gen-key

gpg — list-secret-keys — keyid-format LONG

gpg — output C:\\Test\\mule_pub.gpg — export mule@gmail.com

gpg — export-secret-keys 9D8465F3677F9D863EA15D151D1625CEE931CC85 > C:\\Test\\mule_private.gpg

using this key 9D8465F3677F9D863EA15D151D1625CEE931CC85

you can generate the private.gpg file on the given folder.

The file are generated on the given location.

MuleSoft:

  1. Take listner and configure it.
  2. Take a transform message.

3. Now take the pgp encrypt from pallete and configure it.

Configuration steps:

  1. In this you can speciy any key id according to you.In the fingerprint you can add this value 1D1625CEE931CC85 this also we generated from bit bash.

and also given your mule_pub.gpg that generated with help of git bash.

2. Here, we will used the pgp encrypt. So, the the data will be encrypt whatever the original payload you are sending that will not be in readable format.

3.When we used pgp encrypt connector we will get the output as below.

4. the configuration is given in the above steps.

5. Now, we are using pgp decrypt and its configuration.

6. This will decrypt your message whatever you send in payload the original,it will in readable format.

7. Now,we have to configure it and in this we have to passphrases option. I used the Pankaj@22

8. No using pgp decrypt we will get te orginal payload whatever we have sent.

9. hit the url in the postman you get the final response as below.

Conclusion:

The original message and signed digest are encrypted by using a one-time secret key created by the sender.The secret key is encrypted by using a receiver’s public key.

By using mulesoft how we can acheive the PGP Encryption and Decryption for the security.

--

--

Pankaj Badi

Hello Techies, I always want to learn new things and acquire skills as there is no end for learning and growing