C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Encrypt data in XML file


Posted Date: 12 Mar 2007    Resource Type: Code Snippets    Category: XML

Posted By: Balamurali Balaji       Member Level: Diamond
Rating:     Points: 10



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");





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Reading an XML File
Previous Resource: Get a chunk of the Xml File using Xpath classes
Return to Discussion Resource Index
Post New Resource
Category: XML


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use