Data encryption with Core Data in iOS

后端 未结 3 1445
执念已碎
执念已碎 2021-01-01 00:59

I just need a confirmation on this.

Is it correct to say that, with the iPhone 3GS and above, any data written to the filesystem is encrypted using hardware encrypti

相关标签:
3条回答
  • 2021-01-01 01:20
    [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:@{ NSPersistentStoreFileProtectionKey : NSFileProtectionComplete } error:&error]
    
    0 讨论(0)
  • 2021-01-01 01:20

    No, that is not correct. You will need to enable encryption on the sqlite file. Add the following after you create your persistentStoreCoordinator:

    // Make sure the database is encrypted when the device is locked
    NSDictionary *fileAttributes = [NSDictionary dictionaryWithObject:NSFileProtectionComplete forKey:NSFileProtectionKey];
    if (![[NSFileManager defaultManager] setAttributes:fileAttributes ofItemAtPath:[storeURL path] error:&error]) {
        // Deal with the error
    }
    
    0 讨论(0)
  • 2021-01-01 01:35

    No, your assumption is not correct.

    From the NSPersistentStoreCoordinator class documentation:

    The default value is NSFileProtectionCompleteUntilFirstUserAuthentication for all applications built on or after iOS v5.0. The default value for all older applications is NSFileProtectionNone.

    To enable NSFileProtectionComplete, one would need to add the NSPersistentStoreFileProtectionKey with NSFileProtectionComplete to the options NSDictionary when calling the addPersistentStoreWithType:configuration:URL:options:error: method.

    Keep in mind that this file encryption is only enabled when the user has set a passcode.

    0 讨论(0)
提交回复
热议问题