使用 EncryptedCoreData 加密现有的未加密核心数据,导致现有应用程序更新时出现无效密码错误

问题描述 投票:0回答:0

我在苹果应用商店上有一个使用核心数据的实时 iOS 应用程序。 现在我想使用 EncryptedCoreData (https://github.com/project-imas/encrypted-core-data 2) 加密核心数据。 我成功地在我的项目中实现了相同的功能,并且它在全新安装时运行良好,但是当我尝试用当时使用加密核心数据的新应用程序覆盖未使用加密核心数据的现有应用程序时出现错误 Error Domain=EncryptedStoreErrorDomain Code=6000 “Incorrect passcode” UserInfo={NSLocalizedDescription=Incorrect passcode, NSUnderlyingError=0x6000039e4810 {Error Domain=NSSQLiteErrorDomain Code=26 “(null)” UserInfo={EncryptedStoreErrorMessage=文件不是数据库}}}

 var failureReason = "There was an error creating or loading the application's saved data."
            do {
            let options: [AnyHashable: Any] = [
                EncryptedStorePassphraseKey: key as Any,
                EncryptedStoreDatabaseLocation: sqliteURL,
                NSMigratePersistentStoresAutomaticallyOption: true,
                NSInferMappingModelAutomaticallyOption: true
//                    NSPersistentStoreFileProtectionKey: FileProtectionType.complete
            ]
            let desc = try EncryptedStore.makeDescription(options: options, configuration: nil)
            container.persistentStoreDescriptions = [desc]
            
        } catch {
            var dict = [String: Any]()
            dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
            dict[NSLocalizedFailureReasonErrorKey] = failureReason
            dict[NSUnderlyingErrorKey] = error as NSError
            Log.d(dict)
        }
    }
    

我如何解决这个问题,我想以这种方式实现加密核心数据,以便现有用户(那些拥有未加密数据库的用户)不会受到影响,并且应该将数据库转换为加密核心数据而不会丢失他们的数据。

ios encryption core-data core-data-migration encrypted-core-data-sql
© www.soinside.com 2019 - 2024. All rights reserved.