Mobile

+916350664837

DataWeave Cryptography

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 NameDescription
MD5Computes the MD5 hash and transforms the binary result into a hexadecimal lower case string.
SHA1Computes the SHA1 hash and transforms the result into a hexadecimal, lowercase string.
hashwithComputes the hash value of binary content using a specified algorithm.
HMACBinaryComputes an HMAC hash (with a secret cryptographic key) on input content.
HMACWithComputes an HMAC hash (with a secret cryptographic key) on input content, then transforms the result into a lowercase, hexadecimal string.
DW Crypto Functions

1. MD5 Crypto : It Computes the MD5 hash and transforms the binary result into a hexadecimal lower-case string.

Required ParamsDescription
ContentInput Data or content in Binary format.
MD5 Parameters

Example

Input Request and Transformation

Output

2. SHA1 : It Computes the SHA1 hash and transforms the result into a hexadecimal, lowercase string.

Required ParamsDescription
ContentA Binary input value to encrypt.
SHA1 Required Params

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 namesDescription
MD2The MD2 message digest algorithm as defined in RFC 1319.
MD5The MD5 message digest algorithm as defined in RFC 1321.
SHA-1, SHA-256, SHA-384, SHA-512Hash 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.
hashwith Algorithm Names
Required ParamsDescription
ContentThe binary input content to hash.
AlgorithmThe name of the algorithm to use to calculate the hash value of content. This value is a String. Defaults to SHA-1.
hashwith Parameters

Example

Input Request and Transformation

Output

4. HMACBinary : It Computes an HMAC hash (with a secret cryptographic key) on input content.

Required ParamsDescription
SecretThe secret cryptographic key (a Binary) used when encrypting the content).
ContentThe input content, a Binary value.
AlgorithmThe 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.
HMAC Binary Parameters

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 ParamsDescription
secretThe secret cryptographic key (a Binary) used when encrypting the content).
contentThe input content, a Binary value.
algorithmBy default, HmacSHA1 is used. Other valid values are HmacSHA256 and HmacSHA512.
HMACWith Required Parameters

Example

Output

References :

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

Leave a Reply

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

Related Post