0

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?

Potherca
  • 13,207
  • 5
  • 76
  • 94
TATN
  • 1,249
  • 2
  • 12
  • 26
  • 1
    possible duplicate of [Enable iOS On-Disk Encryption](http://stackoverflow.com/questions/15139305/enable-ios-on-disk-encryption) – staticVoidMan May 22 '14 at 08:39

1 Answers1

2

"However, the moment I unlocked the device, I were able to open the file, and it was unencrypted."

That's exactly what the file encryption does. The the encryption/decryption takes place closer to the metal so as far as users and apps are concerned it's unencrypted once the device is unlocked.

Garry
  • 1,291
  • 1
  • 11
  • 19