---
title: Mule Message Encryption with JCE Keystore - Part 2
description: How to create a Keystore and use it for encryption.
image: https://blog.avenuecode.com/hubfs/social-suggested-images/MuleSoft-mules.jpg
---

[AvenueCode.com](https://avenuecode.com) [News](https://avenuecode.com/news) [Contact](https://avenuecode.com/contact)

[![Avenue Code Snippets Logo](https://blog.avenuecode.com/hubfs/Avenue%20Code%20New%20Logos%20-%202023/AC-Snippets---Black.png)](https://blog.avenuecode.com/?hsLang=en-us) *menu*

- Technology
  
  [Cloud](https://blog.avenuecode.com/blog/topic/cloud?hsLang=en-us) [Delivery Infrastructure](https://blog.avenuecode.com/blog/topic/delivery-infrastructure?hsLang=en-us) [Web Experience](https://blog.avenuecode.com/blog/topic/web-experience?hsLang=en-us) [Agile Mindset](https://blog.avenuecode.com/blog/topic/agile-mindset?hsLang=en-us) [Quality First](https://blog.avenuecode.com/blog/topic/quality-first?hsLang=en-us)
  
  [Design](https://blog.avenuecode.com/blog/topic/design?hsLang=en-us) [Solution Architecture](https://blog.avenuecode.com/blog/topic/solution-architecture?hsLang=en-us) [Data & ML](https://blog.avenuecode.com/blog/topic/data-and-machine-learning?hsLang=en-us) [Mobile Experience](https://blog.avenuecode.com/blog/topic/mobile-experience?hsLang=en-us)
- [Whitepapers](https://blog.avenuecode.com/blog/topic/whitepapers?hsLang=en-us)
- [Spotlight](https://blog.avenuecode.com/blog/topic/spotlight?hsLang=en-us)
- [Extraordinary Women in Tech](https://blog.avenuecode.com/blog/topic/extraordinary-women-in-tech?hsLang=en-us)
- [Avenue Code Culture](https://blog.avenuecode.com/blog/topic/avenue-code-culture?hsLang=en-us)

- [Cloud](https://blog.avenuecode.com/blog/topic/cloud?hsLang=en-us)
- [Design](https://blog.avenuecode.com/blog/topic/design?hsLang=en-us)
- [Delivery Infrastructure](https://blog.avenuecode.com/blog/topic/delivery-infrastructure?hsLang=en-us)
- [Solution Architecture](https://blog.avenuecode.com/blog/topic/solution-architecture?hsLang=en-us)
- [Web Experience](https://blog.avenuecode.com/blog/topic/web-experience?hsLang=en-us)
- [Data & ML](https://blog.avenuecode.com/blog/topic/data-and-machine-learning?hsLang=en-us)
- [Agile Mindset](https://blog.avenuecode.com/blog/topic/agile-mindset?hsLang=en-us)
- [Mobile Experience](https://blog.avenuecode.com/blog/topic/mobile-experience?hsLang=en-us)
- [Quality First](https://blog.avenuecode.com/blog/topic/quality-first?hsLang=en-us)
- [Whitepapers](https://blog.avenuecode.com/blog/topic/whitepapers?hsLang=en-us)
- [Spotlight](https://blog.avenuecode.com/blog/topic/spotlight?hsLang=en-us)
- [Extraordinary Women in Tech](https://blog.avenuecode.com/blog/topic/extraordinary-women-in-tech?hsLang=en-us)
- [Avenue Code Culture](https://blog.avenuecode.com/blog/topic/avenue-code-culture?hsLang=en-us)

# [Mule Message Encryption with JCE Keystore - Part 2](https://blog.avenuecode.com/mule-message-encryption-with-jce-keystore)

- [Tweet](https://twitter.com/share)

*perm\_identity* [Anupam Gogoi](https://blog.avenuecode.com/mule-message-encryption-with-jce-keystore/author/anupam-gogoi?hsLang=en-us)

*schedule* 3/8/17 5:00 PM

> This is the second part of my previous [post](https://blog.avenuecode.com/mule-jce-encryption/?hsLang=en-us) on Encryption using Mule. In the previous post in the **JCE Encrypter configuration,** I did not use **Keystore**. This week, I will create a **Keystore** and use it for encryption.

## **Getting Our Hands Dirty**

First we will create a **Keystore** using **Keytool** that comes with **JDK**. After that we will create a simple project and use the generated keystore for message encryption.

## **Create Keystore**

**JDK** comes with its inbuilt tool **Keytool** to create **keystores**. First, let’s create a keystore using the native **Keytool**.

Let’s create a temporary directory. I have created a temporary directory named **encryption** as shown below:

![screenshot-at-2016-12-10-20-45-42.png](https://blog.avenuecode.com/hs-fs/hubfs/Images/Blog/screenshot-at-2016-12-10-20-45-42.png?width=636&height=318&name=screenshot-at-2016-12-10-20-45-42.png)

Now let’s execute the following command:   
`keytool -genseckey -keystore aes-ackeystore.jck -storetype jceks -storepass acstorepass -keyalg AES -keysize 128 -alias ackey -keypass ackeypass`

After execution of the command a keystore **aes-ackeystore.jck** is generated in the directory. Basic things to point out in the command are as follows:

**Name of the keystore**: aes-ackeystore.jck

**Password of the keystore**: acstorepass

**Name of the key**: ackey

**Password of the key**: ackeypass

These elements constitute the principal information that we need to configure our **JCE Encrypter** using keystore.

# **Create a Simple Mule Project**

Please refer to the previous [post](https://blog.avenuecode.com/mule-jce-encryption/?hsLang=en-us) on Anypoint Enterprise Security module installation. 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>  
```

Please note that I have copied the generated **keystore** (in the previous step) to the resource folder of the project. Here is a screenshot of the project structure:

![ps.png](https://blog.avenuecode.com/hs-fs/hubfs/Images/Blog/ps.png?width=288&height=482&name=ps.png)

## **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 diagram of the flow.

![flow.png](https://blog.avenuecode.com/hs-fs/hubfs/Images/Blog/flow.png?width=636&height=205&name=flow.png)

## **Digging Into JCE Encryption**

### Step 1

First let’s configure a global **Encryption** element.

![global-element1.png](https://blog.avenuecode.com/hs-fs/hubfs/Images/Blog/global-element1.png?width=625&height=625&name=global-element1.png)

Do mind it to select the Default Encryptor dropdown as **JCE*\_ENCRYPTER***. I have named the global element as **JCE\_Keystore**.

Then select the **JCE Encrypter** tab and configure it as shown in the diagram,

![jce-encrypter-config.png](https://blog.avenuecode.com/hs-fs/hubfs/Images/Blog/jce-encrypter-config.png?width=623&height=627&name=jce-encrypter-config.png)

## **Step 2**

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

![encryption-palette-config.png](https://blog.avenuecode.com/hs-fs/hubfs/Images/Blog/encryption-palette-config.png?width=636&height=402&name=encryption-palette-config.png)

In the **Connector Configuration** please select the global encryption element(**JCE\_Keystore**) 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 MEL expression here to encrypt some part of the payload too*. And that’s it! No more configuration is needed; you are ready to go.

### 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 labelled as **Decrypt**. It’s nothing but an **Encryption palette** found under the **Security category of Mule palettes**. Here is the configuration:

![decrypt-config.png](https://blog.avenuecode.com/hs-fs/hubfs/Images/Blog/decrypt-config.png?width=636&height=412&name=decrypt-config.png)

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

# **Testing**

Now, let's run the project! After running the project, send a POST request with JSON payload. I am using **Postman** for this operation. Upon observing in the Anypoint console, you can see the encrypted message as well as decrypted message:

![testting.png](https://blog.avenuecode.com/hs-fs/hubfs/Images/Blog/testting.png?width=636&height=287&name=testting.png)

Sample log in Anypoint console:

```
INFO  2016-12-10 21:23:26,602 [[springbeanexample].HTTP_8081.worker.01] org.mule.api.processor.LoggerMessageProcessor: XjeegDtusFQSovOSxqZgr1j5oCUYypD4/7X6NjworIQ=  
INFO  2016-12-10 21:23:26,613 [[springbeanexample].HTTP_8081.worker.01] org.mule.api.processor.LoggerMessageProcessor: {  
    "name":"anupam"
}
```

Hope this is useful to some of our readers! Feel free to add your questions in the comments below. All source code can be found [here](https://github.com/anupamgogoi0907/muleapps/tree/master/springbeanexample).

[![Explore our Mulesoft Solutions](https://no-cache.hubspot.com/cta/default/2564010/93379104-44a7-436c-922a-cd5251085db5.png)](https://cta-redirect.hubspot.com/cta/redirect/2564010/93379104-44a7-436c-922a-cd5251085db5)

---

### Author

# Anupam Gogoi

 Anupam Gogoi is an Integration Engineer at Avenue Code. He has been working in software development for about 9 years, implementing solutions in Java technologies as well as in SOA domain. He is a hardcore JAVA and MIDDLEWARE evangelist.

---

### Related Posts

### New Horizons for Solution Architects

[READ MORE](https://blog.avenuecode.com/new-horizons-for-solution-architects?hsLang=en-us)

### How to Use Circuit Breaker Resilience in Your API Integration

[READ MORE](https://blog.avenuecode.com/how-to-use-circuit-breaker-resilience-in-your-api-integration?hsLang=en-us)

### How to Run Rust from Python

[READ MORE](https://blog.avenuecode.com/how-to-run-rust-from-python?hsLang=en-us)

### Deep Dive into MuleSoft Internals - API Tracking

[READ MORE](https://blog.avenuecode.com/what-you-need-to-know-about-api-tracking-in-mulesoft?hsLang=en-us)

### Leave a Comment!

### Avenue Code Social

[![Facebook Icon](https://blog.avenuecode.com/hubfs/Images/Blog/facebook.png?t=1486470796564)](https://www.facebook.com/avenuecode)

[![Twitter Icon](https://blog.avenuecode.com/hubfs/Images/Blog/twitter.png?t=1486470796842)](https://twitter.com/AvenueCode)

[![LinkedIn Icon](https://blog.avenuecode.com/hubfs/Images/Blog/linkedin.png?t=1486470796556)](https://www.linkedin.com/company/avenue-code)

### Newsletter

Want to stay on top of all tips and news from Avenue Code?

### Popular Snippets

![ac-logo-inverted.svg](https://blog.avenuecode.com/hubfs/Images/Logos/ac-logo-inverted.svg "ac-logo-inverted.svg")

### About Us

- [Who We Are](https://www.avenuecode.com/who-we-are)
- [What We Do](https://www.avenuecode.com/what-we-do)
- [Portfolio](https://www.avenuecode.com/portfolio)
- [Partners](https://www.avenuecode.com/partners)
- [News](https://www.avenuecode.com/news)
- [Events](https://www.avenuecode.com/events)
- [Blog](https://blog.avenuecode.com/)
- [Contact](https://www.avenuecode.com/contact)

### Our Offices

San Francisco

[+1 415 766 4178](tel:+553125161448) [ac.inquiries@avenuecode.com](mailto:brazil.info@avenuecode.com)

Belo Horizonte

[+55 31 2516 1448](tel:+553125161448) [brazil.info@avenuecode.com](mailto:brazil.info@avenuecode.com)

São Paulo

[+55 11 3205 3232](tel:+553125161448) [brazil.info@avenuecode.com](mailto:brazil.info@avenuecode.com)

### We're Hiring!

- [Belo Horizonte](https://www.avenuecode.com/who-we-are)
- [New York](https://www.avenuecode.com/what-we-do)
- [San Francisco](https://www.avenuecode.com/portfolio)
- [São Paulo](https://www.avenuecode.com/partners)

---

©2015 - 2017 Avenue Code

[![Facebook Icon](https://blog.avenuecode.com/hubfs/Images/Icons/facebook-2.png)](https://www.facebook.com/avenuecode) [![Twitter Icon](https://blog.avenuecode.com/hubfs/Images/Icons/twitter-2.png)](https://twitter.com/AvenueCode) [![LinkedIn Icon](https://blog.avenuecode.com/hubfs/Images/Icons/linkedin-2.png)](https://www.linkedin.com/company/avenue-code) [![Glassdoor Icon](https://blog.avenuecode.com/hubfs/Images/Icons/glassdoor-icon-1.png)](https://www.glassdoor.com/Overview/Working-at-Avenue-Code-EI_IE456173.11,22.htm) [![YouTube Icon](https://blog.avenuecode.com/hubfs/Images/Icons/youtube-2.png)](https://www.youtube.com/user/AvenueCodePlay)

/\*\* DISQUS SCRIPTS \*\*/ Please enable JavaScript to view the [comments powered by Disqus.](http://disqus.com/?ref_noscript)

© 2026 Avenue Code

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Anupam Gogoi",
    "url" : "https://blog.avenuecode.com/author/anupam-gogoi"
  },
  "datePublished" : "2017-03-08T20:00:00.000Z",
  "headline" : "Mule Message Encryption with JCE Keystore - Part 2",
  "image" : [ "https://blog.avenuecode.com/hubfs/social-suggested-images/MuleSoft-mules.jpg" ],
  "mainEntityOfPage" : {
    "@id" : "https://blog.avenuecode.com/mule-message-encryption-with-jce-keystore",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://blog.avenuecode.com/hubfs/Avenue%20Code%20New%20Logos%20-%202023/Avenue%20Code-primary%20versions_LOGO%20HORIZONTAL%20group%201-7.png"
    },
    "name" : "Avenue Code"
  }
}
```