I'm trying to encrypt a file on my iPad using NSFileManager. This is the code:
NSString* encryptedFilePath = [dirPath stringByAppendingPathComponent:@"encryptedDummyData.txt"];
[[NSFileManager defaultManager] createFileAtPath:encryptedFilePath
contents:[@"blah blah blah blah blah" dataUsingEncoding:NSUTF8StringEncoding]
attributes:[NSDictionary dictionaryWithObject:NSFileProtectionComplete
forKey:NSFileProtectionKey]];
The file was generated on the device, but it was not encrypted.
I made sure that the "Data Protection" enabled under "Project Navigator / Capabilities".
I also tried NSFileProjectionCompleteUnlessOpen
and NSFileProtectionCompleteUntilFirstUserAuthentication
with no luck.
The only "progress" that I made was that if I locked down the device after the app had started, then I wouldn't be able to access the file with iExplorer. However, the moment I unlocked the device, I were able to open the file, and it was unencrypted.
So, does NSFileManager encrypt a file at all? Or does it only block the user from accessing the file when the device is locked down?
If it can encrypt the file, then what am I missing?