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
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
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

Migrate, Modernize and Build Java Web Apps on Azure: This live workshop will cover methods to enhance Java application development workflow.

Kubernetes in the Enterprise: The latest expert insights on scaling, serverless, Kubernetes-powered AI, cluster security, FinOps, and more.

A Guide to Continuous Integration and Deployment: Learn the fundamentals and understand the use of CI/CD in your apps.

Related

  • Implementing Cryptography (PGP And JCE) Module With MuleSoft
  • Cryptography Module in Mule 4
  • Asymmetric JCE Cryptography API Using RSA Algorithm in Mule 4
  • Symmetric JCE Cryptography in Mule 4

Trending

  • Demystifying Distributed Systems: A Beginner’s Guide
  • Converting ActiveMQ to Jakarta (Part 1)
  • The Future of Java: Virtual Threads in JDK 21 and Their Impact
  • Unlocking the Power of Streaming: Effortlessly Upload Gigabytes to AWS S3 With Node.js
  1. DZone
  2. Coding
  3. Java
  4. Mule Message Encryption With JCE

Mule Message Encryption With JCE

How to ensure your messages in Mule are encrypted using the Anypoint platform and the Java Cryptography Extension.

Anupam Gogoi user avatar by
Anupam Gogoi
·
Jan. 08, 17 · Tutorial
Like (4)
Save
Tweet
Share
10.2K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

“Don't reinvent the wheel”, that’s the principle Mule applies when it comes to Mule Message Security. Anypoint Enterprise Security is a suite that comes bundled with all the necessary modules and methods for applying security to Mule Service Oriented Architecture (SOA) implementations and Web services.

Objectives

My main concern regarding security was Mule Message Encryption. Mule provides three extraordinary Encryption Strategies:

  • JCE Encrypter: encrypts stream, byte[] or string.
  • XML Encrypter: encrypts string, encrypts individual fields using xpath expressions.
  • PGP Encrypter: encrypts stream, byte[] or string.

In this blog post I will try to explain how to configure Anypoint Studio for applying encryption strategies to mule messages using the JCE Encrypter.

Getting Your Hands Dirty

Let’s get our hands dirty. I will try to explain everything starting from the installation of Anypoint Enterprise Security. Also I would like to point out the troubleshooting during the installation process.

Installation of Anypoint Enterprise Security

I am using Mule 3.8 EE for this experiment. Please take a look at this link for the installation guide in detail. Here is a screenshot:

Installation

Please select the Premium bundle and proceed. In my case I could not install the software initially. If the same problem continues in your case, uncheck the “Contact all update sites during install to find required software” checkbox.

After successful installation, restart your Anypoint studio. You should see the following components under the security group palettes.

Encryption Mule Palettes

Now you are ready to go!

Create a Mule Maven Project

Let’s create a simple Mule Maven project using Anypoint Studio. The most important point is to add the following repository in the pom.xml file.

<repository>
   <id>mulesoft-public</id>
   <name>MuleSoft Public Repository</name>
   <url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
   <layout>default</layout>
</repository>

Creating a Simple Flow

Let’s create a simple flow. The scenario is as follows: we send some JSON data to an HTTP endpoint. Then the JSON data is encrypted using JCE Encryption Strategy, and we log the encrypted data. After that we simply decrypt the encrypted data and log it. Here is a diagram of the flow.

Simple Flow

Digging Into JCE Encryption

From Wikipedia:

“The Java Cryptography Extension ( JCE) is an officially released Standard Extension to the Java Platform and part of the Java Cryptography Architecture. JCE provides a framework and implementation for encryption, key generation and key agreement, and Message Authentication Code (MAC) algorithms.”

Step 1

First let’s configure a global Encryption element.

JCE Global Configuration

Do mind it to select the Default Encryptor dropdown as JCE_ENCRYPTER. I have named the global element as JCE.

Step 2

Now after configuring the global Encryption element in step 1, let’s configure the Encryption component (labeled as JCE Encryption in the flow. This is a Encryption palette found under the Security category of Mule palettes). Here is the screen shot:

Configure Encryption

In the Connector Configuration please select the global encryption element(JCE) that we have defined in step 1. In the Operation dropdown select Encrypt. In the Input Reference field I am putting the whole payload (JSON data) for encryption. Do remember that you can use the MEL expression here to encrypt some part of the payload too. As we are using JCE_ENCRYPTER in this example, let us configure it. Select the Define attributes radio button in the JCE encrypter Strategy Configuration for operation category.

Key: It must be a 16 digit phrase.

Key Password: (whatever you wish)

Algorithm: Choose an algorithm from the dropdown list.

Encryption Mode: Choose from the dropdown list.

That’s it. You are ready to go. There is another way to make it more secure using Keystore. I will show you later in another post.

Step 3

In the step 2 we have encrypted the message. Now let’s decrypt the encrypted message. Here we are going to configure the component labeled as Decrypt payload. It’s nothing but a Encryption palette found under the Security category of Mule palettes. Here is the configuration:

Configure Decryption

The configuration is almost same as for encryption. The only difference is the Operation: Decrypt.

Testing

Now let us run the project. After running the project, send a POST request with JSON payload. I am using Postman for this operation. On observing it in the Anypoint console, you can see the encrypted message as well as decrypted message.

Testing

Please find the source code here.

N.B: Use mvn eclipse:eclipse to import the maven dependencies.

Java Cryptography Extension

Opinions expressed by DZone contributors are their own.

Related

  • Implementing Cryptography (PGP And JCE) Module With MuleSoft
  • Cryptography Module in Mule 4
  • Asymmetric JCE Cryptography API Using RSA Algorithm in Mule 4
  • Symmetric JCE Cryptography in Mule 4

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
  • 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: