Decrypt XML using Symmetric key in C#

In the previous article we have discussed, how to encrypt XML element using Symmetric key. This is a continuation to previous article.


  • Add a reference to System.Security.dll to project
  • Include System.Security.Cryptography and System.Security.Cryptography.Xmlnamespace to your project
  • XML decryption  allows you to read sensitive XML, without worrying about the data being easily read.
  • This procedure decrypts an XML element using the Advanced Encryption Standard (AES)algorithm, also known as Rijndael.
  • When AES is used to encrypt XML data the same key is used to decrypt the xml data

Encrypt an XML element with the previously generated key using the techniques described in How to: Encrypt XML Elements with Symmetric Keys.
Find the element (defined by the XML Encryption standard) in an XmlDocument object that contains the encrypted XML and create a new XmlElement object to represent that element.

Create an EncryptedData object by loading the raw XML data from the previously created XmlElement object.

Create a new EncryptedXml object and use it to decrypt the XML data using the same key that was used for encryption.

Replace the encrypted element with the newly decrypted plaintext element within the XML document.

Let’s look at the example for implementing the same.
This example assumes that a file named “test.xml” exists in the same directory as the compiled program. It also assumes that “test.xml” contains a “socialsecurityno” element. You can place the following XML into a file called test.xml and use it with this example.

© 2015, www.techkatak.com. All rights reserved.