Encrypt Data In Xml File

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Encrypt Data In Xml File as PDF for free.

More details

  • Words: 148
  • Pages: 2
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 person.xml.

     Bala      Trendz

// The following code encrypts the person element in the input XML file and produces encrypted file.

// Load this XML file System.Xml.XmlDocument myDoc = new System.Xml.XmlDocument(); myDoc.Load(@"c:\person.xml"); // Get a specified element to be encrypted System.Xml.XmlElement element =  myDoc.GetElementsByTagName("person")[0] as System.Xml.XmlElement; // Create a new TripleDES key.  System.Security.Cryptography.TripleDESCryptoServiceProvider tDESkey =  new System.Security.Cryptography.TripleDESCryptoServiceProvider(); // Form a Encrypted XML with the Key System.Security.Cryptography.Xml.EncryptedXml encr = new  System.Security.Cryptography.Xml.EncryptedXml(); encr.AddKeyNameMapping("Deskey", tDESkey); // Encrypt the element data System.Security.Cryptography.Xml.EncryptedData ed =  encr.Encrypt(element,"Deskey"); // Replace the existing data with the encrypted data System.Security.Cryptography.Xml.EncryptedXml.ReplaceElement(element,  ed, false); // saves the xml file with encrypted data myDoc.Save(@"c:\encryptedpersons.xml");

Related Documents

Encrypt Data In Xml File
November 2019 9
Xml Data Template
May 2020 3
Encrypt > Passwd
July 2020 11
G Encrypt
August 2019 19