Dietmar Schwarz Webers
Dietmar Schwarz Webers

Reputation: 635

iOS CoreData and AES 256 encryption

I have a CoreData with user information, as Password and other critical information. I need to encrypt this information with AES 256. Looking around I have seen that there are many information about how to do this on OSX, but not on iOS. Can anyone help with this?

Upvotes: 1

Views: 782

Answers (1)

codester
codester

Reputation: 37189

In iOS 5 and later Core Data by default uses NSFileProtection to protect persisted data.

You should use NSPersistentStoreFileProtectionKey to encrypt data of your store.

NSDictionary *storeOptions = @{NSPersistentStoreFileProtectionKey  : NSFileProtectionComplete};

if (![coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[self storeURL] options:storeOptions error:&error]){
     [self presentError:error];
 }

This will automatically encrypt the data of your core data.

But if you want to encrypt selected attributes you can check this code.It is for iOS and uses AES algorithm for encryption.

Upvotes: 2

Related Questions