Jump to content
  • Advertisement
Sign in to follow this  
CodeMachine

[java] How to "encrypt" a XML-file?

This topic is 4366 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I have an XML-file which holds highscores for a game of mine. I now want the user to be unable to changes this higscore list manually. How do you best solve this problem? 1. "Encrypt" the XML-file? 2. Save a check-sum in the XML-file? / Kind Regards [Edited by - CodeMachine on October 5, 2006 3:09:53 PM]

Share this post


Link to post
Share on other sites
Advertisement
I would go with option 2), maybe like this :


1. create your empty .xml high-score file, and calculate a md5() of the empty contents (just the nodes , default hiscore names, maybe without the processing instruction).

2. Store the md5() hash inside a node in the .xml file once you calculate it.

3. When it comes time to save the highscore list within your game

3.1. open the .xml and read the md5() hash node
3.2. replace the md5() hash node content with empty string and precalc the md5() of the xml file
3.3. compare the two hash codes, and resest the high-score files if they don't mach.
3.4. if they match then just save the new scores, precalc the md5() hash , refresh the md5 node content and save the .xml file

This should do it ! :)

Share this post


Link to post
Share on other sites
Alternatively, you can use any encryption scheme you want on the xml data, and then base64 encode the encrytped data.

To read it back, simply convert from base64 to the encrypted data and unencrypt.

The reason for the base 64 encoding is that XML forbids characters greater then a certain value, so that is the easiet way around the problem. Keep in mind that your files will more or less double in size....

Share this post


Link to post
Share on other sites
More simply, why bother. The only person that will see the high scores is the person owning the computer. Maybe a couple of friends. Unless you are having some sort of competition, then it is really a waste of time. And if you are having a competition, you should use a high score server instead.

Share this post


Link to post
Share on other sites
Quote:
Original post by CaptainJester
More simply, why bother.


Now I DO want this kind of security, else I would NOT have posted my question.

Share this post


Link to post
Share on other sites
Thanks for your answers Pro-XeX & Hard Rock.

Hard Rock, is there a good tutorial out there?
Or maybe you have time to construct an example? :)

/ Kind Regards

Share this post


Link to post
Share on other sites
The thing is that I want to:
1. Read XML file (to a Document object).
2. Decrypt the Document object.
3. Make changes (XPath/DOM).
4. Encrypt it.
5. Save it to file.

/ Kind Regards

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you do not want the user to be able to edit the file, you might consider just not using a file format that is so easy to edit. It seems that this is a case where XML is not well suited to the job. You could just as easily use a binary file, and not have to worry overmuch about the user changing the highscores. In fact, it seems like it would be far easier than encrypting the file or mucking about with base64.

Share this post


Link to post
Share on other sites
The reason I am using XML is because it's very easy to retrieve/sort/add/edit data using XPath/DOM.
I think I have to calculate a CRC32 or something for all the nodes in the XML-file, and store this CRC-value in a separate node.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!