0

So I'm making a small game with C#. And in this game you can save and load.

I use an XML file to store a player's data. But an XML file can be easily edited by any text editor.

So is there a way to encrypt or encode the XML file, and when i load it into my program, it returns back to normal XML code?

or will i have to make my own encryption ?

I have tried searching for a solution, but i did not find an understandable one.

Thanks very much.

  • 1
    http://stackoverflow.com/questions/202011/encrypt-decrypt-string-in-net – bluetoft Jun 25 '13 at 22:00
  • Why do you need to encrypt it, why would the user want to edit the player data? – Shaun Wilde Jun 25 '13 at 22:05
  • @ShaunWilde, to cheat? –  Jun 25 '13 at 22:17
  • You could at least list a few links you found but didn't understand. Now people are probably going to find the same links. – Gert Arnold Jun 25 '13 at 22:20
  • @Amy let them. Unless there is some monetary reward I wouldn't bother and if there was I'd store the game data on a central server, which they can't access. Only put the effort where there is value in doing so. – Shaun Wilde Jun 30 '13 at 04:43
  • @ShaunWilde, I agree. I was answering your question, "why would the user want to edit the player data". The answer is, "to cheat". –  Jul 01 '13 at 15:29

1 Answers1

4

You can use the EncryptedXml class from System.Security.Cryptography.Xml

See http://msdn.microsoft.com/en-us/library/system.security.cryptography.xml.encryptedxml.aspx

It has a full example toward the bottom.

Note that you can't prevent determined users from disassembling your application, getting the encryption keys, and decrypting it themselves. It would help to obfuscate your code, but you cannot prevent them from decrypting it, if they're knowledgeable enough.

  • is it also possible for web apps. I am using xml file to save some data. is it possible when user opens xml file ,user won't be able to see xml data. – Arun Sharma Mar 12 '15 at 15:24