Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encrypting and decrypting som.xml file

Status
Not open for further replies.

PIAS

Programmer
Nov 2, 2005
38
SI
How can i Encrypt som xml file and than Decrypt it?

I need a code in C#...

Thanks!

PIAS
 
Sorry,

the contents of an xml file,
so it would be useless to others...

PIAS
 
You can check my homepage where you can download my TextSecurity dynamic link library. Help files integrated into VS .NET are included, as well as a sample application (VB .NET, but easily ported to C#).

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
I'm desperate, im searching for two day's a way how to make contents of XML file unreadable(contents of xml file can not be recognizable)

I hawe data set and from that dataset i save data in to XML file. If i open now this xml file with notepad, i can see data in text.

Now i vant to save this data in xml file but in the way that no one would be able to recognize data in it...

Any solutions?

Thanks!

PIAS
 
If you simply add a reference to my above mentioded DLL and use the then available namespace System.Security you can write code similar to this:

Code:
Private TextSecurity tSecurity = New TextSecurity
·
·
tSecurity.EncryptTextFile(mySourceFile, myTargetFile)
File.Delete(mySourceFile)
File.Move(myTargetFile, mySourceFile)
·
·

This encrypts the file (any textbased file like XML/HTML/TXT, not just .txt), deletes the original, and renames the target as the original again. The DLL uses TripleDES and MD5 encoding so it's pretty secure.

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Since you want to encrypt only part of your XML file, you'll need to do something like this for each element you want to protect.

1. Use the UnicodeEncoding class to convert the string you want to encrypt into an array of byte.
2. Use the RijndaelManaged (pronounced "Rain-Doll") class to encrypt the byte array. You'll need two additional byte arrays: One for the key, and one for the initialization vector (makes the key more unique). Protect both these values, as you'll need them to decrypt.
3. Use the ToBase64String method on the Convert class to change the resulting encrypted byte array into something that can be stored in XML.
4. Write the string to your XML DOM.

To decrypt:
1. Read the base64 encoded string from the XML
2. Use the FromBase64String method on the Convert class to change it to a byte array.
3. Use the RijndaelManaged class to decrypt the byte array to a cleartext byte array. You'll need the key and initialization vector used to encrypt it.
4. Use the UnicodeEncoding class to convert the byte array back into a string.

Hope this helps.
Chip H.



____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top