2012-03-13 65 views
6

我只需要对此进行确认。使用iOS中的核心数据进行数据加密

对于iPhone 3GS及以上版本,写入文件系统的数据是否使用硬件加密进行加密是否正确?通过简单地在文件系统上创建XXX.sqlite文件,存储在其中的数据已经被加密。

也为了进一步的安全NSFileProtectionComplete提供?

谢谢。

+0

AFAIK只有在手机有密码且处于锁定状态时才是这种情况。 – Rog 2012-03-14 00:06:45

+0

也看看这个WWDC会议https://developer.apple.com/itunes/?destination=adc.apple.com.4088379409.04088379411.4092394151?i=1595505280 – Rog 2012-03-14 00:13:30

回答

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 
} 
+0

如果我这样做,我的sqlite不能访问.. – Jitendra 2014-03-26 13:46:51

+1

我认为这将无法加密包含应用程序数据的预写日志(WAL)文件。这与用于sqlite的日志模式有关,但是它现在处于默认状态。有关详细信息,请参阅Mike Rose以及此博客文章的以下评论:http://www.hopelessgeek.com/2014/10/10/core-data-and-data-protection/ – jeffmax 2015-07-14 16:52:28

+2

@edsko是否必须打开数据保护功能以及为了完成核心数据文件加密? – RandomGuy 2016-11-29 18:24:17

3

不,您的假设是不正确的。

从NSPersistentStoreCoordinator类文档:

The default value is NSFileProtectionCompleteUntilFirstUserAuthentication for all applications built on or after iOS v5.0. The default value for all older applications is NSFileProtectionNone.

要启用NSFileProtectionComplete,一个需要与NSFileProtectionComplete添加NSPersistentStoreFileProtectionKey到选项调用addPersistentStoreWithType时的NSDictionary:配置:网址:选项:错误:方法。

请记住,只有当用户设置了密码时才启用此文件加密。

7
[_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:@{ NSPersistentStoreFileProtectionKey : NSFileProtectionComplete } error:&error] 
+1

这是正确的做法。 – augustzf 2014-08-20 10:36:53

+0

这似乎是为我工作的出于好奇,有没有人认为这是不正确的Apple文档?我唯一看到的这个选项值是在https://developer.apple.com/library/mac/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSPersistentStoreCoordinator_Class/#//apple_ref/doc/constant_group/Spotlight_External_Record_Elements中,它没有看起来正确。 – jeffmax 2015-07-09 13:58:15