In this example we will use Jasypt in mule to encrypt clear text passwords in property files. But you could use Jasypt to encrypt all sorts of things e.g. encrypt all in a property file and not just the password.

What is Jasypt

Jasypt is an open source java library which allows the developer to add basic encryption capabilities to their projects with minimum effort, without the need of having deep knowledge on how cryptography works. We use Jasypt to encrypt clear text password in mule property files.


First, you need to download the Jasypt distribution, because we shall use it later to encrypt our password. As of this writing, the latest version is 1.9.2, and you can get it at

Then start a new mule project with maven support

New mule project dialog

Open the project pom file and add the following Maven dependencies, this is the dependencies that include the Jasypt libraries.


Configure jasypt beans

Next we configure the jasypt java beans as spring beans in our mule config file as the first thing after the namespaces.

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="" xmlns:context="" xmlns="" xmlns:doc=""
 <!--                                                                               -->
 <!-- Configuration for encryptor, based on environment variables.          -->
 <!--                                                                                   -->
 <!-- In this example, the encryption password will be read from an         -->
 <!-- environment variable called "JASYPT_MULE_PASSWORD" which, once    -->
 <!-- the application has been started, could be safely unset.                  -->
 <!--                                                                                   -->
 <spring:bean id="environmentVariablesConfiguration"
   <spring:property name="algorithm" value="PBEWithMD5AndDES" />
   <spring:property name="passwordEnvName" value="JASYPT_MULE_PASSWORD" />
 <!--                                                                                   -->
 <!-- This will be the encryptor used for decrypting configuration values.  -->
 <!--                                                                               -->
 <spring:bean id="configurationEncryptor"
   <spring:property name="config" ref="environmentVariablesConfiguration" />

 <!--                                                                               -->
 <!-- The EncryptablePropertyPlaceholderConfigurer will read the        -->
 <!-- .properties files and make their values accessible as ${var}.         -->
 <!--                                                                               -->
 <!-- Our "configurationEncryptor" bean (which implements                   -->
 <!-- org.jasypt.encryption.StringEncryptor) is set as a constructor arg.   -->
 <!--                                                                               -->
 <!--  The property file should be placed in /src/main/resources            -->
 <!--                                                                               -->
 <spring:bean id="propertyConfigurer"
   <spring:constructor-arg ref="configurationEncryptor" />
   <spring:property name="locations">
<!-- Here comes your normal flow definition -->


Make encrypted password

Now we encrypt your password, with the Jaspyt distribution you downloaded in the start of this post. [JASYPT_HOME] is that place where you unpacked the distribution. As an example, my distribution is located at /home/tools/jasypt/ which then becomes my [JASYPT_HOME]. Now goto [JASYPT_HOME]/bin and run the following command:

$ ./ input="thisisjasyptencrypted" password=mymajorsecretpassword algorithm=PBEWithMD5AndDES


  • input is the password you want to encrypt e.g. the password for your database or similar,
  • password is the super password that Jasypt use to crypt og decrypt your original password and
  • algorithm is the algorithm of your choice. Jasypt support various algoritm but we stick with PBEWithMD5AndDES

The command should give the following output:


Runtime: Oracle Corporation OpenJDK 64-Bit Server VM 25.91-b14


algorithm: PBEWithMD5AndDES
input: thisisjasyptencrypted
password: mymajorsecretpassword



Set the environment variable

If you use this in a Mule Runtime (out of Anypoint Studio), you have to configure an environment variable.


$ export JASYPT_MULE_PASSWORD=mymajorsecretpassword

or to store the variable permanent write it to /etc/environment file, in a name=value format, e.g. JASYPT_MULE_PASSWORD=mymajorsecretpassword


In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab. Then enter JASYPT_MULE_PASSWORD=mymajorsecretpassword

The JASYPT_MULE_PASSWORD variable can be removed when Mule is started if you feel it will be safer that way.

If you’re uncertain how to create environment variables for your system, then google it or submit a question on Given the many systems and ways to create it, so going through all of them is out of scope for this blog post.

Test Jasypt configuration

Now we build a test flow so we can test our Jasypt implementation, it is a simple flow with just an HTTP and a logger component. The result should be that the decrypted password is written to the console.

Drag an HTTP component onto the “canvas” and make an HTTP configuration just use the default host and port 8081. In the Logger component just write ${jasypttest} And now you can start the application. Just make sure that this XML code is below the spring bean configuration.

Flow XML:

<http:listener-config name="HTTP_Listener_Configuration" host="" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="jasyptsampleFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <!-- write the decryptet password to the console   -->
        <logger message="${jasypttest}" level="INFO" doc:name="Logger"/>

The above XML flow should look like this in the visual designer.

The above XML flow should look like this in the visual designer.

Before starting the flow, you have to set a runtime environment if you are using Anypoint Studio or any other Eclipse-based development IDE. Run -> Run Configurations -> Environment (tab)

Remember the environment variable

Then you can run the sample application. And go to http://localhost:8081/ to start the flow we just created. Now look in the log in anypoint studio and you can see the decrypted password (thisisjasyptencrypted).

Log output showing the decrypted password


Be aware of that this solution still has the master password in plain text; the advantage is that you have separated the password to the database, SFTP host or what ever password/property you have encrypted from the development environment. You will have to set the environment variable for every environment you have. Where I came from this was a good solution because the developer does not have access to the servers there were only a few people there has this access and they stood for the password creation and setting up the environment variable and other environment specific properties.

Get the Jasypt Sample project code on GitHub.

Jack Petersen

Integration Consultant at Redpill Linpro

Jack Petersen works as an integration specialist and Java developer, from our office in Copenhagen, creating integrations in Mule and Camel for various customers.

Mulesoft Enterprise Standalone Runtime on Raspberry Pi 3 with docker

The Raspberry Pi 3 is the third generation Raspberry Pi, on this i will be installing Mulesoft enterprise runtime standalone with latest Java 8 running inside a Docker container. The Instance will register itself with Anypoint platform ... [continue reading]

Norwegian IPv6 year in review

Published on January 24, 2017

How to use Mule as a web server

Published on January 19, 2017