Encryption in DataWeave: HMACBinary and toBase64 functions

Updated: Sep 4

Github repository with the Mule Project can be found at the end of the post.

The main objective of this post is to show how we can implement a field level encryption for a JSON payload in MuleSoft using DataWeave.

The motivation for this implementation came from a demand where the requirement was to mask certain confidential information (say 2 out of 10 fields) in a JSON payload before inserting the object into a database. Since the code was already implemented, we have a limited degree of freedom for bringing something new (like a connector) on board. The only thing that was implementable was a tweak in the already implemented DataWeave script which was performing some operations on the payload.