Hiding (or encrypting) app resources?

前端 未结 3 1126
我寻月下人不归
我寻月下人不归 2021-01-02 10:15

I\'ve developing a Cocoa app that has certain resources (images) which I wish to protect, but still display. Normally one would just place these in the resources folder, bu

相关标签:
3条回答
  • 2021-01-02 10:51

    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.

    0 讨论(0)
  • 2021-01-02 11:08

    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 data
    NSData* data=[NSKeyedArchiver archivedDataWithRootObject:theArray];
    

    Use NSKeyedUnarchiver to retrieve the array again.

    0 讨论(0)
  • 2021-01-02 11:13

    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.

    0 讨论(0)
提交回复
热议问题