TATN
TATN

Reputation: 1269

File Encryption with NSFileManager

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?

Upvotes: 0

Views: 906

Answers (1)

Garry
Garry

Reputation: 1341

"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.

Upvotes: 2

Related Questions