Jump to content
  • Advertisement
Sign in to follow this  
Telamon

[.net] Encrypting Game Resources

This topic is 4855 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

I'm writing a roguelike game in C# and I would like to encrypt all of my game resources (bitmaps and XML files mainly) to prevent people from peeking into the game content and posting spoilers online. I recognize that it's really hard to secure game resources on the client, so I'm just looking for something easy that I can do to make it harder for anyone inclined to poke around. Is there an easy way to do this using something in the Cryptography namespace? I'ven't really much experience with anything like this. Do I gain anything by writing my own encryption routine over using a common one?

Share this post


Link to post
Share on other sites
Advertisement
Yeah, making a truly secure system can be a real bastard... you'll never stop the truly hard-core peeps from reflecting and/or debugging your code to figure out what is going on, so really the data can only be as safe as its key(s). And if you just stick your symmetric key in your code as a constant byte array or string, it is trivial to pull it out, so you could try to "scramble" it a bit with a function before using it (hey, at least its better than nothing).

In answer to your question, yes, you can use the Cryptography namespace to easily incorporate encryption capabilities into your game. You don't gain anything by writing your own encryption algorithms (there are plenty of good ones provided for you), however I find it is nice to wrap the functionality for both ease-of-use and reusability reasons.

Have a look at this nice article (with code) to get you started:
http://www.dotnetthis.com/Articles/Crypto.htm



As an aside that you may find interesting, I am looking at using asymmetric (ie "public/private key") encryption for the content of an online multiplayer game... the main reason for this being that while content can be inspected easily, it can't be altered or substituted without going through us. The way this works being that content is encrypted before distribution with the private key, and therefore can only be decrypted by the public key, which ships with the game and can be freely visible. However the inverse is also true... the content cannot be altered, saved, and re-encrypted in a format suitable for consumption by the game without the private key (NB: if it is encrypted with the public key, it is no good without the private key to decrypt it).

Of course, this does not help your concern about peeking at content and "spoilers", but what it does do is help stop people using hacked content (such as using bright-yellow textures to make enemies stick out the proverbial dog's nuts in dark locations or colour-keying for aim-bots to target, or tiny models so that you aren't as visible to enemies, etc) to gain an advantage. And for those who think this would be disgustingly slow in terms of loading... well, you may be right :)


[edit] - haven't posted in so long i forgot how to link :P

Share this post


Link to post
Share on other sites

You could always convert your XML Data to binary files, Using serialization to send the files to binary instead of XML. As to the BMP why not add them as resources to an assembly, then they should get compiled into the .dll file.

Share this post


Link to post
Share on other sites
I'd go with serializating. It's extremely simple in .NET as well with the [Serializable()]. You'll just need to make little tools to assist you in making the binary files [smile]. But why would you want to encrypt the game data? Having it accessible promotes expansion and extending your game to the public.

Share this post


Link to post
Share on other sites
I'm writing a roguelike game and a big part of playing a roguelike is discovering new things. So ideally the player would be running across cool items he's never seen before all the time.

I feel it takes a lot of the mystery out of the game if one can go online and download the game's entire item manifest (which people do for roguelikes, apparently).

Diablo II is a good example of this. Every unique item you find in that game is cool, until you go online and see what all the best items are. Then whenever you find something, it's more like, "yeah, this is ok, I guess, but not as cool as Ultimate Weapon X".

Share this post


Link to post
Share on other sites
Quote:
Original post by Rob Loach
I'd go with serializating. It's extremely simple in .NET as well with the [Serializable()].


There's no reason why you couldn't take advantage of either binary or xml serialization as well as do encryption (in fact you are crazy not to use the built-in serialization... saves you so much tooling around writing load/save code).

For binary serialization, either implement ISerializable and perform encryption/decryption per data field, or (preferably) mark your classes with the Serializable attribute, serialize all your objects to a memory stream and then perform encryption/decryption on the entire stream as you feed it to a filestream.

For xml serialization, again serialize the objects to a memory stream, then perform encryption/decryption on the entire stream as you feed it to a filestream.

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!