Hiding (or encrypting) app resources? Hiding (or encrypting) app resources? objective-c objective-c

Hiding (or encrypting) app resources?


Simple solution:

Merge all files into one big data-file, optionally using 'salts'.
Then retrieve specific files with something like this:

NSData *dataFile = [NSData dataWithContentsOfFile:filePath];  NSData *theFile = [dataFile subdataWithRange: NSMakeRange(startPos,endPos)];

This does not really protect the files,
but prevents people simply dragging out the resources.
At least, the data-file is unusable, certainly with salts.

Another solution:

Create NSData object for every resource.
Add all objects to a NSMutableArray.
Convert the array to one big NSData object.
Write the NSData object to a file.
And add it to the resources folder.

Your app can then read the data-file.
And retrieve the array with the resources.

// Convert array to dataNSData* data=[NSKeyedArchiver archivedDataWithRootObject:theArray];

Use NSKeyedUnarchiver to retrieve the array again.


In order for you to protect the images in one big file, you can just dump the image data to a NSData object sequentially.

If you want, you can use either salts, as previously mentioned, or you can use AES encryption method, as shown here.

Then, you will have to either save the image files structurally (using an NSArray or similar) or record the image offsets so you can retrieve the image data blocks correctly.

This has some drawbacks, specially if your images change over time. That way you will have to monitor those changes and re-structure the file accordingly.

On other option is for you to simply mask the image files by changing name/extension to one of your choice. This will leave some users away from touch.

Finally, you can search for some archiving frameworks using zip like functions and keep the images there (as Blizzard uses in their MPQ format). This will be the best option (since it provides you with encryption methods and it abstracts you of the mechanisms of encryption and archiving) but it may not be easy to find such a framework.


Why do you want to protect the images? It goes without saying that anything you display can be recorded with a screenshot, so if you're trying to protect the images from the person viewing them, there isn't much point.

If you still want to protect them (say, some images should only be available to certain people), encrypting them on disk might be an option. I'm not an Objective-C guy, but this1 seems like a good place to look.