2012-03-13 67 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