【发布时间】:2014-06-04 22:04:35
【问题描述】:
我正在尝试使用 NSFileManager 加密 iPad 上的文件。这是代码:
NSString* encryptedFilePath = [dirPath stringByAppendingPathComponent:@"encryptedDummyData.txt"];
[[NSFileManager defaultManager] createFileAtPath:encryptedFilePath
contents:[@"blah blah blah blah blah" dataUsingEncoding:NSUTF8StringEncoding]
attributes:[NSDictionary dictionaryWithObject:NSFileProtectionComplete
forKey:NSFileProtectionKey]];
文件是在设备上生成的,但未加密。
我确保在“项目导航器/功能”下启用了“数据保护”。
我还尝试了NSFileProjectionCompleteUnlessOpen 和NSFileProtectionCompleteUntilFirstUserAuthentication,但没有成功。
我取得的唯一“进步”是,如果我在应用程序启动后锁定设备,那么我将无法使用 iExplorer 访问该文件。但是,在我解锁设备的那一刻,我能够打开文件,而且它是未加密的。
那么,NSFileManager 会加密文件吗?还是仅在设备锁定时阻止用户访问文件?
如果它可以加密文件,那我错过了什么?
【问题讨论】:
标签: ios encryption nsfilemanager