Encrypting a JSON element

Facebooktwittergoogle_plusredditpinterestlinkedinmail

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.

Untitled

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 :-
http://security-update-site-1.4.s3.amazonaws.com/

Untitled

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.

Untitled

 

Corresponding Mule flow will be as follows :-

Untitled

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.

Untitled

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 !!!

Untitled

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.

Untitled

Conclusion…..

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.

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Anirban Sen Chowdhary

Anirban Sen Chowdhary is an information technology professional currently working on Java/J2ee, Esb and Integration platform. For more information, please visit http://anirbansenchowdhary.com and you can also follow https://twitter.com/Anir37

You may also like...

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>