{{announcement.body}}
{{announcement.title}}

Implementing Dataweave Crypto With Mulesoft

DZone 's Guide to

Implementing Dataweave Crypto With Mulesoft

MuleSoft provides various functions to encrypt the fields within Dataweave transformation and it can be achieved using various algorithms like MD5, SHA1, etc.

· Integration Zone ·
Free Resource

MuleSoft provides various functions to encrypt the fields within Dataweave transformation and it can be achieved using various algorithms like MD5, SHA1, etc.

To use Crypto in the Datawave, one must import Crypto by using import dw::Crypto

HMACBinary

HMACBinary function will compute the HMAC hash with a Cryptographic Secret key on input data.

Parameter Description
secret Cryptographic key in binary format for encryption.
content Input Data or content in Binary format.
algorithm Hashing Algorithm. By default, HmacSHA1 is used.

Example

Input

JSON


Output

Plain Text
 




xxxxxxxxxx
1


1
{
2
  "HMACBinary": "\u0002\u0014=\ufffdg\u0017\ufffd\u001a\u0006M\u0007\ufffd%\ufffd\ufffdʝ%\ufffdt\ufffd\ufffd\ufffd\u001d\ufffds\ufffd\ufffd\u000bž)"
3
}



HMACWith

HMACWith function will compute the HMAC hash with a Cryptographic Secret key on input data and transform the message into lowercase and hexadecimal string.

Parameter Description
secret Cryptographic  key in binary format for encryption.
content Input Data or content in Binary format.
algorithm Hashing Algorithm. By default HmacSHA1 is used.

Example

Input

JSON
 




x


 
1
%dw 2.0
2
import dw::Crypto
3
output application/json
4
---
5
{
6
    HMACWith: Crypto::HMACWith("632423477" as Binary,"Test123456" as Binary,"HmacSha512")
7
}



Output

Plain Text
 




xxxxxxxxxx
1


1
{
2
  "HMACWith": "e4a249fd0f737e0c455d1f250e94312d33f839a5a22f4cb66abeca3a93ff5d4039eb0e685490fc3a3b34bab371f9e255f00f7ac533b8d5175e4bd0cd6a3ad43b"
3
}



MD5

MD5 function will compute the MD5 hash and transform the binary message into lowercase and hexadecimal string.

Parameter Description
content Input Data or content in Binary format.

Example

Input

JSON
 




xxxxxxxxxx
1


1
%dw 2.0
2
import dw::Crypto
3
output application/json
4
---
5
{
6
    MD5: Crypto::MD5("632423477" as Binary)
7
}



Output

Plain Text
 




xxxxxxxxxx
1


1
{
2
  "MD5": "de1c3e94be10bd302f8728cef823970c"
3
}



SHA1

SHA1 function will compute the SHA1 hash and transform the message into lowercase and hexadecimal string.

Parameter Description
content Input Data or content in Binary format.

Example

Input

JSON
 




xxxxxxxxxx
1


 
1
%dw 2.0
2
import dw::Crypto
3
output application/json
4
---
5
{
6
    SHA1: Crypto::SHA1("632423477" as Binary)
7
}



Output

Plain Text
 




xxxxxxxxxx
1


1
{
2
  "SHA1": "e7224fd2a1b66f04759bfddba8c244d52d64675a"
3
}



HashWith

HashWith function will compute hash depending on the algorithm provided. 

Parameter Description
content Input Data or content in Binary format.
algorithm Supported algorithms are SHA1, SHA256, SHA384, SHA512, MD2, MD5 etc.

Example

Input

JSON
 




xxxxxxxxxx
1


1
%dw 2.0
2
import dw::Crypto
3
output application/json
4
---
5
{
6
    HashWith: Crypto::hashWith("632423477" as Binary,"MD2")
7
}



Output

JSON
 




xxxxxxxxxx
1


1
{
2
  "HashWith": ",s\ufffds\u0013\ufffd\ufffd\ufffd\ufffd\ufffd1*`gc\ufffd"
3
}


Now, you know that how we can implement the Crypto module in dataweave transformation.

Topics:
crypto, dataweave, hmac, integration, mulesoft, tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}