I am working on an ios application that uses copyrighted pdf files. I am looking for some simple ways to obfuscate the files for security that won't require me to go through the additional Mass Market CCATS encryption review process but will also ensure the copyright holders I've done my bit to keep their data safa. I password protect the files of course, but I want to bring it a step or two further. Is there a simple method to XOR or otherwise hash or obfuscate a pdf file I'll be hosting on my server, then have the ios device download it and restore it to a regular password protected pdf file using objective-c code so it can save it in the documents directory (I'm not worried about its security on the device as much as when it's sitting on the server). I assume that this would be the same for any filetype.
So for clarification I'm looking for a simple XOR or Hash obfuscation/encryption method on my desktop that has corresponding objective c code the ios device can use to quickly decode my files after download and save it to the documents directory.
Thanks so much!
here is an answer about CCATS limitations for reference ... Need to apply for CCATS if using simple XOR cipher?
However you're downloading the file, you're probably ending up with an NSData? If so, wherever you probably have something like this:
[myData writeToFile:...]
Just dash through all the bytes and apply your XOR. Supposing it were a dense 8-bit pattern, that'd just be:
/* assuming myData is mutable... take [data mutableCopy] if required */
uint8_t *bytes = (uint8_t *)[myData mutableBytes];
for(int index = 0; index < [myData length]; index++)
bytes[index] ^= 0xe8; // or whatever your mask is
Which suggests the most trivial way to apply a longer pattern:
uint8_t *bytes = (uint8_t *)[myData mutableBytes];
uint8_t pattern[] = {0xe8, 0xf4, 0x98, 0x32, 0x63}; // or whatever
const int patternLengthInBytes = 5;
for(int index = 0; index < [myData length]; index++)
bytes[index] ^= pattern[index % patternLengthInBytes];
It'd be slightly faster to proceed in 32-bit steps, but the saving to disk is probably going to be the only thing that has any significant sort of cost and that's at least very clear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With