OGeek|极客世界-中国程序员成长平台

标题: ios - 为现有 sqlite 上的持久存储管理器更改 NSPersistentStoreFileProtectionKey [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 15:49
标题: ios - 为现有 sqlite 上的持久存储管理器更改 NSPersistentStoreFileProtectionKey

当应用程序在后台调用 addPersistentStoreWithType 时,我的 sqlite 文件有时不可用,我收到此错误:

[Model createPersistentStoreCoordinatorWithStoreURL:] line 387 $ sqlite encryption state NSFileProtectionCompleteUntilFirstUserAuthentication error : Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x1560e540 {NSUnderlyingException=authorization denied, NSSQLiteErrorDomain=23}

我发现这是因为文件仍然受到保护(默认为 NSFileProtectionCompleteUntilFirstUserAuthentication,因此在用户重启后第一次解锁设备后, protected 数据可用)。我觉得这行为不正确,因为我有大量的崩溃,我无法想象有很多人在野外重启后仍然锁定他们的设备。

因此,我现在正在添加我的持久存储协调器,并像这样调整配置

NSDictionary *options = @{
        NSMigratePersistentStoresAutomaticallyOption : @YES,
        NSInferMappingModelAutomaticallyOption : @YES,
        NSPersistentStoreFileProtectionKey : NSFileProtectionNone
    }; 

问题:

  1. 如果设备被锁定,这是否能确保文件在后台也可用?
  2. 如果我更改 NSPersistentStoreFileProtectionKey,这会破坏 sqlite(/内的数据)吗?
  3. 我没有在数据库中存储敏感数据,但是,您在使用 NSFileProtectionNone 时是否发现安全问题?



Best Answer-推荐答案


  1. 是的,会的。这就是这把 key 的作用。
  2. 不,不会。我有一个带有默认保护 key 的持久存储协调器,然后将 NSFileProtectionComplete 添加到它,数据就可以了。
  3. 是的。如果有人可以访问您的数据库文件,他可以轻松阅读它。查看这篇文章:https://github.com/project-imas/encrypted-core-data#strings-comparison

关于ios - 为现有 sqlite 上的持久存储管理器更改 NSPersistentStoreFileProtectionKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36450555/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4