ma11hew28
ma11hew28

Reputation: 126427

Core Data Encryption?

I have entities Account and CreditCard in Core Data. An account can have multiple creditCards. Each creditCard has an number. How do I encrypt the number?

I know I could use Keychain Services without Core Data, but could I use them together? The reason I want to use Core Data instead of something like NSUserDefaults is because I want to handle multiple accounts. I haven't used Keychain Services, so I'm not sure if it'd be good for multiple accounts.

Upvotes: 1

Views: 587

Answers (2)

dardi
dardi

Reputation: 39

You can change the attributes that you want to encrypt to type Transformable, and create your own NSValueTransformer that encrypts when transformedValue is called and decrypts when reverseTransformedValue is called.

Transformable attributes: https://developer.apple.com/library/prerelease/ios/samplecode/PhotoLocations/Introduction/Intro.html

Example of decrypt/encrypt AES256: https://gist.github.com/m1entus/f70d4d1465b90d9ee024

Upvotes: 1

Mundi
Mundi

Reputation: 80273

You can store your keychain object in Core Data by transforming it into an NSData object. This is not all that trivial, as you need to transform it back and forth correctly. Check out these documentation documents about Non-Standard Persistent Attributes to help you.

Upvotes: 2

Related Questions