Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Secure contents in Documents directory

Can anyone help me to make the contents of my Documents directory secure?

like image 728
Jatin Patel - JP Avatar asked Sep 19 '11 12:09

Jatin Patel - JP


2 Answers

Use:

- (BOOL)writeToFile:(NSString *)path options:(NSDataWritingOptions)mask error:(NSError **)errorPtr

with one of the file protection options:

NSDataWritingFileProtectionComplete (iOS 4.0)
NSDataWritingFileProtectionCompleteUnlessOpen (iOS 5.0)
NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication (iOS 5.0)

See: Apple Documentation

NSDataWritingFileProtectionComplete

In this case, the file is stored in an encrypted format and may be read from or written to only while the device is unlocked. At all other times, attempts to read and write the file result in failure.

Note: Doing your own encryption raises the problem of key storage and the best answer there is to use the Keychain. Key handling is the biggest problem and the NSData methods handle that.

like image 107
zaph Avatar answered Nov 07 '22 02:11

zaph


We cannot secure the file in documents directory. We can store the file in temp folder of the device. This cannot be accessed by anyone

like image 40
Roopa Avatar answered Nov 07 '22 01:11

Roopa