{{announcement.body}}
{{announcement.title}}

Cryptography Module in Mule 4

DZone 's Guide to

Cryptography Module in Mule 4

In this article, we discuss how to use JCE Encrypt and JCE decrypt connectors in Mule to better manage security in your application.

· Security Zone ·
Free Resource

Steps to Use JCE Encrypt and JCE Decrypt Connectors

  1. Check if Crypto module is available in Mule Palette. If not, download it from exchange.
  2. Then, search for JCE in the Mule palette. The Crypto module should be visible now.

Mule pallette
3. To use Jce encrypt and decrypt connector, we need a keystore.

  • Generate a keystore using following command:  

keytool.exe -genseckey -alias jksvalue -keyalg Blowfish -keystore encKeystore.jceks -keysize 128 -storeType JCEKS

Alias name : jksvalue 

Algorithm used : Blowfish

Keystore file name : encKeystore

Keystore file type : jceks

 Using JCE encrypt

Keep the keystore and key passwords. These passwords need to be use in JCE configuration. 

  • Store the generated encKeystore.jceks file in resource folder of mule project.
  • Take Jce encrypt connector from the Mule palette and do the module configuration as shown below : 

Module configuration


Module configuration

We are using a symmetric key (same key for encryption and decryption). Add the symmetric key details using the + button in the above image. 

Adding symmetric key details


Configuring JCE key

Do the remaining configuration just shown in the above image. Note that the algorithm should be the same, which we used for creating the Keystore and the Key id in the above two images should be identical

Check the advanced section. 

Checking Keystore and key Id

The output of this component below is the encrypted value : 

Encrypted value

The encrypted value has a few characters, which cannot be shared or we cannot type it. Here comes the encoding part to convert the encrypted string to Base64 format.  

Encoding can be done using the below transformation:

Payload to Base 64

The output of encoding is below: 

Encoding below

In the same way, we have to first decode the payload and then decrypt it:

Encoding payload

Decrypting payload

Topics:
encryption ,mule 4 ,security ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}