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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
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
Partner Zones AWS Cloud
by AWS Developer Relations
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
Partner Zones
AWS Cloud
by AWS Developer Relations
  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.

Jitendra Bafna user avatar by
Jitendra Bafna
CORE ·
Apr. 12, 17 · Tutorial
Like (6)
Save
Tweet
Share
10.40K 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.

Popular on DZone

  • [DZone Survey] Share Your Expertise and Take our 2023 Web, Mobile, and Low-Code Apps Survey
  • Building a RESTful API With AWS Lambda and Express
  • Introduction to Spring Cloud Kubernetes
  • Spring Cloud

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: