iOS中使用Core Data进行数据加密

use*_*637 6 iphone encryption core-data ios

我只需要对此进行确认.

用iPhone 3GS及以上版本来说,写入文件系统的任何数据都是使用硬件加密加密的吗?只需在文件系统上创建XXX.sqlite文件,存储在其中的数据就已经加密了.

还提供进一步的安全性NSFileProtectionComplete

谢谢.

Mic*_*ose 8

[_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:@{ NSPersistentStoreFileProtectionKey : NSFileProtectionComplete } error:&error]
Run Code Online (Sandbox Code Playgroud)


eds*_*sko 7

不,这不正确.您需要在sqlite文件上启用加密.创建后添加以下内容persistentStoreCoordinator:

// Make sure the database is encrypted when the device is locked
NSDictionary *fileAttributes = [NSDictionary dictionaryWithObject:NSFileProtectionComplete forKey:NSFileProtectionKey];
if (![[NSFileManager defaultManager] setAttributes:fileAttributes ofItemAtPath:[storeURL path] error:&error]) {
    // Deal with the error
}
Run Code Online (Sandbox Code Playgroud)

  • @edsko为了完成核心数据文件加密,是否必须在功能中打开Data Protection? (2认同)