We often need to encrypt our sensitive payloads from being exposed to the external world.The major concern that we always have is to protect our data.Encryption is one of the great way to protect the data.But sometimes we need to encrypt a particular element in a payload and not the entire payload.For example, a credit card information in a JSON payload.
How to encrypt an element from a JSON payload ???
Let’s consider we have a JSON payload which have a sensitive information in it like credit card number.Now, we don’t want to encrypt the whole JSON payload, but only the sensitive element credit card number.
Encrypting a particular JSON element.
To encrypt a payload or a part of payload, we need to use Mule security module.
We can install the security plugins in studio using the following link :-
So, we will construct our Mule flow with Mule security <encryption/> to encrypt the element in the JSON element credit card number.
You can see here, we are extracting the element credit card number from the JSON and is encrypted, then it is again updated with the JSON payload.
Corresponding Mule flow will be as follows :-
Testing our application
We will test the application in a REST client like POSTMAN.
We can see here our JSON payload is as input and the credit card number element is completely exposed. Now, whenever this payload will be entering our flow, we will encrypt the element.
So, when we hit the url http://localhost:8081/ we can see in the response, credit card number element is encrypted and it is done without encrypting the entire payload !!!
Though this is not recommended to print the sensitive information using a logger, but here I have printed it in the console just to give an idea on how the element credit card number is getting encrypted.
Here it was a small demonstration encrypting a part of JSON payload with Mule security plugin.We can use this feature to encrypt and protect all the elements that we feel sensitive and risky to exposed to the external world.
Hope you like the article. Please feel free to comment your ideas below comment section.