Mule Message Encryption-XML Encrypter


In the post I have explained how to configure Anypoint Enterprise Security module and also shown how to use the JCE Encrypter. Please read the whole post before stepping into this post. It’s very important.


The main objective of this post is to use the same flow we have used in the post. The flow is as follows. “We send some XML data to an HTTP endpoint. Then the XML data is encrypted using XML 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 Diagram

Step 1

Now configure a global Encryption Element named as XML_Encrypter 

Global Element configuration.

Step 2

In the flow configure the Encrypt component,

Encrypt Element General Config.

In the Connector Configuration please select the global encryption element(XML_Encrypter) that we have defined in step 1. In the Operation dropdown select Encrypt. In the Input Reference field please put the payload. Now  select the encryption strategy as XML_ENCRYPTER. As we are using XML_ENCRYPTER in this example, let us configure it. Select the Define attributes radio button in the XML encrypter Strategy Configuration for operation category.

XML Strategy config.

Here we are encrypting only the name xml element using  Xpath.

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

Decrypt General Config.
Decrypt XML Config.

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

Operation: Decrypt


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

Test Data

Sample result

INFO  2016-12-11 23:27:49,150 [[springbeanexample].HTTP_8081.worker.01] org.mule.api.processor.LoggerMessageProcessor: <?xml version="1.0" encoding="UTF-8"?><book>
	<name><xenc:EncryptedData xmlns:xenc="" Type=""><xenc:EncryptionMethod Algorithm=""/><ds:KeyInfo xmlns:ds="">
<xenc:EncryptedKey xmlns:xenc=""><xenc:EncryptionMethod Algorithm=""/><xenc:CipherData><xenc:CipherValue>w6kq/2uvqK/EX+Z9ROWKMCW+wRwLdehj</xenc:CipherValue></xenc:CipherData></xenc:EncryptedKey></ds:KeyInfo><xenc:CipherData><xenc:CipherValue>DIO/ZC/PrlpdBVnl2uzUTPDuGhXuO1tXF54qH0k70cE=</xenc:CipherValue></xenc:CipherData></xenc:EncryptedData></name>
INFO  2016-12-11 23:27:49,159 [[springbeanexample].HTTP_8081.worker.01] org.mule.api.processor.LoggerMessageProcessor: <?xml version="1.0" encoding="UTF-8"?><book>

Please find the source code here.

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


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s