Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
emorphisgit opened this issue Aug 20, 2020 · 2 comments
Open

Comments

@emorphisgit
Copy link

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.

@iprabhakarpatil
Copy link

Did you find a solution to this? Am facing the same issue.

1 similar comment
@RamyaThirunavukkarasu
Copy link

Did you find a solution to this? Am facing the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants