使用iOS中的Core Data进行数据encryption
我只需要确认一下。
对于iPhone 3GS及以上版本,写入文件系统的任何数据都使用硬件encryption进行encryption,是否正确? 通过简单地在文件系统上创buildXXX.sqlite文件,存储在其中的数据已经被encryption。
也为了进一步的安全NSFileProtectionComplete
提供?
谢谢。
不,这是不正确的。 您将需要在sqlite文件上启用encryption。 在创buildpersistentStoreCoordinator
后添加以下内容:
// 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 }
[_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:@{ NSPersistentStoreFileProtectionKey : NSFileProtectionComplete } error:&error]
不,你的假设是不正确的。
从NSPersistentStoreCoordinator类文档:
对于构build于iOS v5.0或之后的所有应用程序,默认值为NSFileProtectionCompleteUntilFirstUserAuthentication。 所有较旧的应用程序的默认值是NSFileProtectionNone。
要启用NSFileProtectionComplete,在调用addPersistentStoreWithType:configuration:URL:options:error:方法时,需要将带有NSFileProtectionComplete的NSPersistentStoreFileProtectionKey添加到选项NSDictionary中。
请记住,只有当用户设置了密码时,才能启用此文件encryption。