File Encrypt / Decrypt


#1

I’m playing around with generating and reading binary files; all good and working as expected.

At the moment, I’m using a FileOutputStream and using the writeText and writeByte functions.

But now I’m looking at adding in some basic encryption / decryption. Don’t need anything fancy. Just enough to obfuscate to the average end user.

Been having a little play with the BlowFish class, but the penny isn’t dropping… is that the best approach to take? Or is there any other recommendations?


#2

Blowfish is good for symmetric encryption, but it depends what you’re trying to do, and who you’re trying to hide the data from…


#3

Just enough that an average end user won’t go poking around in the files. Or if they do, it would make no sense. Nothing more complex / advanced then that.


#4

Then blowfish would be fine, but if you’re really not worried about security then a simpler (and much, much faster) approach would just be a simple XOR of your data.


#5

That (XOR / mini encryption engine) was something I was thinking about… needs some coffee and sketching out; but shouldn’t be too hard hopefully… should be able to just slot that in there I think.


#6

To further obfuscate your binary data, something I’ve seen done with recent video games is hashing file paths and names when packing your data (would require modifications to JUCE’s binary packing) and generating hashes for the names of desired files at runtime. This way even once the files are decrypted they’ll be named gibberish unless the names can be scraped from scripts or the binary itself and matched to the decrypted names.

In the case of video games, binary resource name hashing also has the benefit of speeding up parsing and loading a huge number of files (say, a ton of models/textures for a game level) since in video games binary data is usually stored as a giant chunk of contiguous data with a hash table pointing to offsets to the data itself.

A real world example of this is the last two Metal Gear Solid games which used a scary-fast game engine built from the ground up. It used XOR encryption for its archives and CityHash for filename hashing (which is a great hashing library, by the way), along with Denuvo anti-tamper combined with Steam for its DRM (which was totally non intrusive to paying customers and delayed pirates by several weeks).

Of course, it did end up getting cracked, the XOR key was extracted, and the filename hashes are being scraped from the executables, game scripts, and brute forcing, but given the ease of implementing these solutions and how long they were able to keep pirates off they might be some things worth looking into.


#8

Thanks Jules, went with a XOR with some bells and whistles, that will do me.

Thanks for that info jonathonracz, will be good for some reading sometime.