DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Using OKTA as Client Provider in Mulesoft
  • Importance Of Anypoint Dedicated Load Balancer in MuleSoft Ecosystem
  • Building a High-Throughput Distributed Sequence Generator Using the Hi-Lo Algorithm
  • MuleSoft MCP and A2A in Production: What 17 Recipes Reveal

Trending

  • Building a Skill-Based Agentic Reviewer with Claude Code: A Practical Guide Using Skills.MD, MCP Servers, Tools, and Tasks
  • A Deep Dive into Tracing Agentic Workflows (Part 1)
  • A Scalable Framework for Enterprise Salesforce Optimization: Turning Outcomes Into an Operating System
  • Exactly-Once Processing: Myth vs Reality
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Implementing Dataweave Crypto With Mulesoft

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.

By 
Jitendra Bafna user avatar
Jitendra Bafna
·
Sep. 03, 20 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
15.1K Views

Join the DZone community and get the full member experience.

Join For Free

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
x
 
1
%dw 2.0
2
import dw::Crypto
3
output application/json
4
---
5
{
6
    HMACBinary: Crypto::HMACBinary("632423477" as Binary,"Test123456" as Binary,"HmacSha256")
7
}


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.

Plain text MuleSoft Algorithm

Opinions expressed by DZone contributors are their own.

Related

  • Using OKTA as Client Provider in Mulesoft
  • Importance Of Anypoint Dedicated Load Balancer in MuleSoft Ecosystem
  • Building a High-Throughput Distributed Sequence Generator Using the Hi-Lo Algorithm
  • MuleSoft MCP and A2A in Production: What 17 Recipes Reveal

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook