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

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

  • How to Convert XLS to XLSX in Java
  • Thread-Safety Pitfalls in XML Processing
  • Loading XML into MongoDB
  • SmartXML: An Alternative to XPath for Complex XML Files

Trending

  • Distributed Consensus: Paxos vs. Raft and Modern Implementations
  • Mastering Fluent Bit: Installing and Configuring Fluent Bit on Kubernetes (Part 3)
  • The Human Side of Logs: What Unstructured Data Is Trying to Tell You
  • Four Essential Tips for Building a Robust REST API in Java
  1. DZone
  2. Coding
  3. Java
  4. Encrypt Mule Message With Anypoint JCE and XML Encrypter

Encrypt Mule Message With Anypoint JCE and XML Encrypter

MuleSoft provides various encryption strategies to encrypt your messages. Security is a very important aspect when it comes to developing integration solutions.

By 
Jitendra Bafna user avatar
Jitendra Bafna
DZone Core CORE ·
Apr. 12, 17 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
10.9K Views

Join the DZone community and get the full member experience.

Join For Free

Security is one of the very important aspects when we are developing integration solutions — especially in the banking and finance sectors. When you want to send your data securely over the channel to third parties, it is very important that you send your data encrypted so it becomes unreadable for unauthorized entities. 

MuleSoft provides various encryption strategies to encrypt your messages.

Encryption strategy Description
JCE encrypter

Encrypts stream, byte[], or string.

XML encrypter

Encrypts string; encrypts individual fields using xpath expressions.

PGP encrypter

Encrypts stream, byte[], or string; applies tighter security (relative to JCE and XML); increases processing load (relative to JCE and XML).

In this article, you will learn about the JCE and XML encrypter.

Please make sure you have installed the enterprise security in Anypoint studio.

JCE Encrypter

Place the HTTP listener in the canvas and open the Properties console.

Click the green + and configure as follows:

  • Host: localhost.

  • Port: 8081.

  • Method: POST.

  • Path: encrypt.

Image title

Drag and drop the encryption component in message processor region and configure it. Click on green Add button, select the Default Encrypter as JCE, and click OK.

Image title

Now, provide input expression and in this case, we will encrypt the whole payload. Select Encrypter to be JCE_ENCRYPTER and Operation to be Encrypt.

Image title

Now, under JCE Encrypter Strategy Configuration, for Operation, select the Define attributes radio button. Provide key and key password (optional). Select Algorithm and Encryption Mode.

Image title

Place the outbound file connector after encryption to save the final encrypted output.

Image title

Field Desscription
Display name It is a unique name for your message processor.
Operation Select Encrypt or Decrypt.
Select encrypter JCE Encrypter.
Key

The key (i.e. password) to decrypt the encrypted data. It must be 16 bytes long.

Key password

If the key is stored in a keystore, enter the passwoard to the keystore.

Algorithm Select algorithm to use to encrypt data.
Encryption mode

Select an encryption code for Mule to use to encrypt the data.

Testing Application

You can use Postman to test the application. The listening URL is http://localhost:8081/encrypt.

Image title

Now, you can verify the output directory where you have stored the final encrypted file.

Image title

Code:

<?xml version="1.0" encoding="UTF-8"?>
<mule
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:encryption="http://www.mulesoft.org/schema/mule/encryption"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/encryption http://www.mulesoft.org/schema/mule/encryption/current/mule-encryption.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
<encryption:config name="Encryption" doc:name="Encryption"/>
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<encryption:config name="Encryption1" doc:name="Encryption"/>
<flow name="securit-appFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/encrypt" allowedMethods="POST" doc:name="HTTP"/>
<encryption:encrypt config-ref="Encryption1" using="JCE_ENCRYPTER" doc:name="Encryption">
<encryption:jce-encrypter key="test123" algorithm="Blowfish" encryptionMode="CBC"/>
</encryption:encrypt>
<file:outbound-endpoint path="src/test/resources/out" responseTimeout="10000" doc:name="File"/>
</flow>
</mule>

XML Encrypter

In this case, you need to select XML Encrypter instead of JCE Encrypter. Under Connector Configuration, select Default Encrypter as XML. Set Encrypter to XML_ENCRYPTER.

Under XML Encrypter Strategy Configuration, for Operation, select the Define attributes radio button. Provide the key and key password (optional). Select Algorithm and Encryption Mode.

In XML Encrypter, you can encrypt a particular field data. You can provide the the XPath of the field that you need to encrypt.

Field Desscription
Display name It is a unique name for your message processor.
Operation Select encrypt or decrypt.
Select encrypter XML encrypter.
Key

The key (i.e. password) to decrypt the encrypted data.

Key password

If the key is stored in a keystore, enter the password to the keystore.

Algorithm Select algorithm to use to encrypt data.
Encryption mode

Select an encryption code for Mule to use to encrypt the data.

Image title

<?xml version="1.0" encoding="UTF-8"?>
<mule
xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:encryption="http://www.mulesoft.org/schema/mule/encryption"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/encryption http://www.mulesoft.org/schema/mule/encryption/current/mule-encryption.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<encryption:config name="Encryption" doc:name="Encryption"/>
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<encryption:config name="Encryption1" doc:name="Encryption" defaultEncrypter="XML_ENCRYPTER"/>
<encryption:config name="Encryption2" defaultEncrypter="XML_ENCRYPTER" doc:name="Encryption"/>
<encryption:config name="Encryption3" defaultEncrypter="XML_ENCRYPTER" doc:name="Encryption"/>
<encryption:config name="Encryption4" defaultEncrypter="XML_ENCRYPTER" doc:name="Encryption"/>
<encryption:config name="Encryption5" defaultEncrypter="XML_ENCRYPTER" doc:name="Encryption"/>
<flow name="securit-appFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/encrypt" allowedMethods="POST" doc:name="HTTP"/>
<encryption:encrypt config-ref="Encryption5" doc:name="Encryption">
<encryption:xml-encrypter key="6237632" xpath="/Emloyees/Employee/CreditCard" algorithm="AES_128"/>
</encryption:encrypt>
<file:outbound-endpoint path="src/test/resources/out" responseTimeout="10000" doc:name="File"/>
</flow>
</mule>

Image title

Now, you know how to secure your message with the JCE and XML encrypter.

Java Cryptography Extension XML

Opinions expressed by DZone contributors are their own.

Related

  • How to Convert XLS to XLSX in Java
  • Thread-Safety Pitfalls in XML Processing
  • Loading XML into MongoDB
  • SmartXML: An Alternative to XPath for Complex XML Files

Partner Resources

×

Comments

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: