Encrypt data in XML file
The following code helps you to encrypt the specified element in an XML file using TripleDES algorithm. In
this code, an element named "person" is encrypted.
The following XML data is stored in a file [Link].
<?xml version="1.0" encoding="UTF8"?>
<persons>
<person>
<name>Bala</name>
<company>Trendz</company>
</person>
</persons>
// The following code encrypts the person element in the input XML file and produces encrypted
file.
// Load this XML file
[Link] myDoc = new [Link]();
[Link](@"c:\[Link]");
// Get a specified element to be encrypted
[Link] element =
[Link]("person")[0] as [Link];
// Create a new TripleDES key.
[Link] tDESkey =
new [Link]();
// Form a Encrypted XML with the Key
[Link] encr = new
[Link]();
[Link]("Deskey", tDESkey);
// Encrypt the element data
[Link] ed =
[Link](element,"Deskey");
// Replace the existing data with the encrypted data
[Link](element,
ed, false);
// saves the xml file with encrypted data
[Link](@"c:\[Link]");