tech savvy
tech savvy

Reputation: 1435

Encrypting existing unencrypted core data using EncryptedCoreData causing invalid passcode error on existing app update

I have a live iOS application on apple app-store which is using the core data. Now I want to encrypt the core-data using EncryptedCoreData (https://github.com/project-imas/encrypted-core-data 2). I am successfully able to implement the same with my project and it working fine for fresh installed but when I tried to override my existing application which is not using the encrypted coredata with the new application which is using the encrypted coredata at that time getting error Error Domain=EncryptedStoreErrorDomain Code=6000 "Incorrect passcode" UserInfo={NSLocalizedDescription=Incorrect passcode, NSUnderlyingError=0x6000039e4810 {Error Domain=NSSQLiteErrorDomain Code=26 "(null)" UserInfo={EncryptedStoreErrorMessage=file is not a database}}}

 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)
        }
    }
    

How I can resolve this issue, I want to implement Encrypted coredata in such a way so the existing user(those having unencrypted DB) does not affect and there DB should be converted into Encrypted core data without losing their data.

Upvotes: 1

Views: 159

Answers (0)

Related Questions