I come from somewhat of a security background. I was thinking of a fast way to protect images in HTML5 applications.
The idea is pretty simple.
Before game compilation
1. Generate a chaotic map, such as the logistic map.
2. Xor your intended image with the chaotic map. This gives you an encrypted result.
3. Save the xor'ed result to a lossless image format, as the original image file.
At runtime
4. Set the context's composite operation to 'source-over'
5. Draw the portion of the chaotic map that you used to encrypt the image to the canvas.
6. Set the context's composite operation to 'xor'
7. Draw your encrypted image to the canvas from earlier.
8. Grab a coffee and smile.
The idea is that an un-encrypted copy of the image is never in RAM at anytime, unless within the memory used for the screen. Of course, they can always rip our graphics from the screen memory (The canvas that's displayed) but modifying our graphics will be highly difficult unless they understand the scheme.
Adding some Fragility to our Scheme:
(Discrete Cat Map, from Wikipedia)
Fragility means one small change leads to a large change. Fragility is very good for DRM. Fragility means our image will be super-sensitive to small modifications, one small change will corrupt the scheme. If a hacker is clever and tries to mess with our image, manipulating pixels will only break the image and prevent the correct image from displaying.
We could probably take our original image use the discrete arnold map before xor-ing it with the logistic map (The arnold map is a chaotic map that makes an orderly image very chaotic in a few discrete steps)
The result of using the discrete arnold map is that in the image's chaotic state, any change by an attacker made to the image will completely ruin it unless the arnold map is first performed to bring our image back to order again.
Preventing SubstitutionThis scheme already does a fairly good job at preventing attackers from substituting their own images in place for ours, effectively modding our game.
We can also however take advantage of redundancy, which is a fancy way of saying "extra space" inside of images.
Now, there are tons of image watermarking and image steganography schemes, so I won't go into them. They're too complex to discuss here and I promised that I would keep this simple.
For this you could use anything from getImageData() to read the hidden data from the image's pixels, btoa()/atob() (Which would get the base64 Data URI of the image allowing you to explicitly read data in the metadata fields of the image, *but this isn't very secure* or rollout your own image parser to read the pixel data.
Watermarking/stegano schemes can be used to encode side information within the image that could be used as a form of digital watermark.
For instance, if you encode a string within an image, in Javascript, you could load this string with Function() or eval() (Please don't use eval(), for the love of Jesus
)
This would let you run code that could possibly be used to validate not only the authenticity of the image, but it could also be used to secretly house critical code of the game, such as code used for databases, or in-app purchasing.
With the above methods, removing or modifying an image would now be as serious as corrupting the game's core code, and small modifications would range anywhere from corrupting the graphics, to causing the game to crash or flagging an anti-tamper mechanism.
DownsidesThe main downside is that transparency isn't supported (You also need a lossless format like PNG and at least with the way that I'm envisioning this transparency won't work), and I'm sure if someone REALLY wanted to modify your game with their own graphics they could easily do so by directly modifying the image source of drawImage() calls directly in your source code if your calls were visible there.
This method however would force a novice Javascript hacker to have a copy of your encrypted assets within memory which would be very useful for proving that their property was stolen from yours.
If an attacker tried to just comment out your calls to drawImage and instead included calls their own graphic sources (Likely to make a mod of your game), they would still need your encrypted information to still be there unless they were clever enough to recreate the missing information added by new Function().
You could use this to possibly threaten them to remove the stolen property or face legal action, proving that it's yours.
However I guess this would mainly just make it super difficult, but not impossible to someone who
1.) Understands your scheme or at least what it tries to do.
2.) Knows Javascript to a degree and knows how new Function() works.
3.) Is patient and willing enough to inspect your code at every step and try to recreate the missing pieces.
There's also a bit of overhead. Ignoring the xor and other fun chaotic map madness. You'll have to make 2 calls to drawImage() for each decryption instead of one, all assuming you decrypt your image on each frame and you don't cheat and try to cache the decrypted result to another offscreen canvas.
...
Please leave your thoughts... I don't have anyone to discuss this with (
To most people around me, this stuff is like Greek to them), I wonder if someone on these forums recognizes what I'm trying to do.