回答
查找,你做addPersistentStoreWithType:configuration:URL:options:
NSURL *storeURL = ...;
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:...];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeURL
options:nil
error:&error])
{
NSLog(@"Add persistent store failed: %@", error);
}
行則附加:
NSDictionary *attributes = @{NSFileProtectionKey: NSFileProtectionComplete};
if (![[NSFileManager defaultManager] setAttributes:attributes
ofItemAtPath:path
error:&error]) {
NSLog(@"File protection failed: %@", error);
}
要知道,你不能在後臺使用的數據庫,可以考慮使用NSFileProtectionCompleteUnlessOpen:
NSFileProtectionComplete
: 該文件存儲在磁盤上的加密格式,在設備鎖定或引導時無法讀取或寫入。NSFileProtectionCompleteUnlessOpen
: 該文件以加密格式存儲在磁盤上。文件可以在設備鎖定時創建,但一旦關閉,在設備解鎖之前不能再次打開。如果文件在解鎖時打開,即使用戶鎖定設備,也可以繼續正常訪問文件。當文件被創建並打開時,性能損失很小,但在寫入或讀取時不會受到影響。這可以通過在設備解鎖時將文件保護更改爲NSFileProtectionComplete
來緩解。
請注意,爲整個應用打開數據保護(只要您可以適應後臺問題)就更簡單了,建議您這麼做:http://stackoverflow.com/questions/18326225/ fmdb-and-encryption/18414100#18414100 –
謝謝!雖然我使用MagicalRecord,但這幫助了我! :) –
這是怎麼用MagicalRecord完成的? – lostintranslation
- 1. 核心數據加密類
- 2. 核心數據加密?
- 3. 核心數據加密
- 4. 核心數據SQLite加密?
- 5. 加密核心數據
- 6. iOS核心數據加密
- 7. 核心數據加密atributes
- 8. 核心數據數據加密
- 9. 核心數據MagicalRecord合併MOCS在線程使用MagicalRecord(https://github.com/magicalpanda)
- 10. 用於加密核心數據的SDK
- 11. 使用MagicalRecord在覈心數據中映射ADN Post實體
- 12. 加密和解密Sqlite文件(使用核心數據)
- 13. 使用iOS中的核心數據進行數據加密
- 14. 加密或部分加密核心數據數據庫?
- 15. 加密核心數據條目
- 16. NSFileProtectionComplete不加密核心數據文件
- 17. 使用核心數據與核心圖
- 18. 使用.NET核心加密字符串
- 19. 核心數據與多個對象,MagicalRecord init與2 sqlite
- 20. HOWTO創造核心數據實體MagicalRecord的saveWithBlock
- 21. MagicalRecord:在後臺線程上設置核心數據堆棧
- 22. 無法指定...在實體MagicalRecord [核心數據]
- 23. 使用CloudKit核心數據
- 24. 使用與核心數據
- 25. iOS:在覈心數據中使用GCD和核心數據
- 26. 核心數據 - iOS上的加密/解密
- 27. 加密通過核心數據訪問的Sqlite數據庫
- 28. 核心數據加載
- 29. 從核心數據加載
- 30. 使用核心數據提取數據
這是一個關於sqlcipher和神奇記錄的問題(http://stackoverflow.com/questions/18365375/ios-magical-record-sqlcipher)。也許這將提供一個適當的解決方案 – casademora