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 开发者_StackOverflow中文版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.
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.
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
精彩评论