Skip to content

Migration Old unencrypted Core database to Encrypted Core Data base. #332

@emorphisgit

Description

@emorphisgit

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

Following is my old code sample

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (persistentStoreCoordinator_ != nil) {
        return persistentStoreCoordinator_;
    }
    else if (!storeUrl)
        return nil;
    
    NSError *error = nil;
    persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel];

        NSDictionary *options = @{
                                        EncryptedStorePassphraseKey : @"123456",
                                        EncryptedStoreFileManagerOption : [EncryptedStoreFileManager defaultManager],
                                        NSMigratePersistentStoresAutomaticallyOption : @YES
                                        };
    
    NSPersistentStore *store = [persistentStoreCoordinator_
                                addPersistentStoreWithType:EncryptedStoreType
                                configuration:nil
                                URL:storeUrl
                                options:options
                                error:&error];
    
    if (!store && error)
    {
        NSLog(@"%@",error.description);
        // Here is the 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}}}
    }
    
    return persistentStoreCoordinator_;
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions