Reputation: 854
I have an iOS application, which stores all downloaded *.pdf
files in its cache. Is there a way to prevent this data from extracting? Encryption or something else? Thanks in advance.
Upvotes: 0
Views: 368
Reputation: 6747
Assuming you want the PDF files from getting extracted on jailbroken devices, the most straight forward approach would be along the following lines:
NSUserDefaults
in state file inside your own app's sandboxYou would probably find the source code here very helpful.
Upvotes: 0
Reputation: 6372
There are actually 2 Documents folders in which your app can store content. One can be extracted, and one is private. Check the accepted answer in this ticket.
Access files in "private Documents" folder transferred with iTunes
Upvotes: 0
Reputation: 35384
You can protect PDF files with a password. I assume you create the PDF files not within the application but externally. For example you can use Preview.app in Mac OS X to secure existing PDF files with a password (Hit Cmd-P, then select PDF in the print menu and there you can set security options. Or even more simple: in the menu choose Export...).
In iOS you can then open the PDF files like this:
CGPDFDocumentRef documentRef = CGPDFDocumentCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:filePath]);
if (!CGPDFDocumentIsUnlocked(documentRef))
CGPDFDocumentUnlockWithPassword(documentRef, password);
...
Upvotes: 1
Reputation: 920
There are quite a few ways to encrypt files, and I'm sure everyone will have an opinion on the best way to do so.
In a project I've recently been working on, we've been using CommonCrypto (https://github.com/AlanQuatermain/aqtoolkit). Just take any NSData, encrypt it, and save it to a file, and vice versa. You can even write an easy Transformer by subclassing NSValueTransformer, which abstracts all of the encryption to one spot and you will never have to worry about it again.
Upvotes: 2