Introduction
• MuleSoft provides multiple functions to encode the Dataweave Transformation fields.
•This can be achieved using different kind of algorithms like MD5, SHA1, hashwith, HMAC Binary and so on.
• To use the crypto module in Dataweave, you should import the Crypto Module in Dataweave as below:
Import dw::Crypto
Functions
Function Name | Description |
MD5 | Computes the MD5 hash and transforms the binary result into a hexadecimal lower case string. |
SHA1 | Computes the SHA1 hash and transforms the result into a hexadecimal, lowercase string. |
hashwith | Computes the hash value of binary content using a specified algorithm. |
HMACBinary | Computes an HMAC hash (with a secret cryptographic key) on input content. |
HMACWith | Computes an HMAC hash (with a secret cryptographic key) on input content, then transforms the result into a lowercase, hexadecimal string. |
1. MD5 Crypto : It Computes the MD5 hash and transforms the binary result into a hexadecimal lower-case string.
Required Params | Description |
Content | Input Data or content in Binary format. |
Example
Input Request and Transformation

Output

2. SHA1 : It Computes the SHA1 hash and transforms the result into a hexadecimal, lowercase string.
Required Params | Description |
Content | A Binary input value to encrypt. |
Example
Input Request and Transformation

Output

3. hashwith : It Computes the hash value of binary content using a specified algorithm. The first argument specifies the binary content to use to calculate the hash value, and the second argument specifies the hashing algorithm to use.
The second argument must be any of the accepted Algorithm names:
Algorithm names | Description |
MD2 | The MD2 message digest algorithm as defined in RFC 1319. |
MD5 | The MD5 message digest algorithm as defined in RFC 1321. |
SHA-1, SHA-256, SHA-384, SHA-512 | Hash algorithms defined in the FIPS PUB 180-2. SHA-256 is a 256-bit hash function intended to provide 128 bits of security against collision attacks, while SHA-512 is a 512-bit hash function intended to provide 256 bits of security. A 384-bit hash may be obtained by truncating the SHA-512 output. |
Required Params | Description |
Content | The binary input content to hash. |
Algorithm | The name of the algorithm to use to calculate the hash value of content. This value is a String. Defaults to SHA-1. |
Example
Input Request and Transformation

Output

4. HMACBinary : It Computes an HMAC hash (with a secret cryptographic key) on input content.
Required Params | Description |
Secret | The secret cryptographic key (a Binary) used when encrypting the content). |
Content | The input content, a Binary value. |
Algorithm | The hashing algorithm. HmacSHA1 is the default. Valid values depend on the JDK version you are using. For JDK 8 and JDK 11, HmacMD5, HmacSHA1, HmacSHA224, HmacSHA256, HmacSHA384, and HmacSHA512 are valid algorithms. For JDK 11, HmacSHA512/224 and HmacSHA512/256 are also valid. |
Example
Input Request and Transformation

Output

5. HMACWith : It Computes an HMAC hash (with a secret cryptographic key) on input content, then transforms the result into a lowercase, hexadecimal string.
Required Params | Description |
secret | The secret cryptographic key (a Binary) used when encrypting the content). |
content | The input content, a Binary value. |
algorithm | By default, HmacSHA1 is used. Other valid values are HmacSHA256 and HmacSHA512. |
Example

Output

References :
https://docs.mulesoft.com/mule-runtime/4.3/dw-crypto