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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Using OKTA as Client Provider in Mulesoft
  • Importance Of Anypoint Dedicated Load Balancer in MuleSoft Ecosystem
  • Implementing Cryptography (PGP And JCE) Module With MuleSoft
  • Attribute Based Access Control for Mulesoft APIs

Trending

  • Analyzing Techniques to Provision Access via IDAM Models During Emergency and Disaster Response
  • The Role of AI in Identity and Access Management for Organizations
  • Scaling Microservices With Docker and Kubernetes on Production
  • Integrating Model Context Protocol (MCP) With Microsoft Copilot Studio AI Agents
  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
DZone Core CORE ·
Sep. 03, 20 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
14.4K 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
  • Implementing Cryptography (PGP And JCE) Module With MuleSoft
  • Attribute Based Access Control for Mulesoft APIs

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!