Search code examples
ioscachingencryptionkeychain

Limits of iOS Keychain usage


In my app, I want to keep very sensitive data persisted on a client in an encrypted cache, and thought of using the keychain.

Potentially, we could end up putting quite a bit of information (a couple of MBs) into this cache and was wondering...

  • Are there any hard limits on the size of data that I can cram into the keychain?
  • Is there another/better place I can store this data? I only need a simple key/value interface similar to NSUserDefaults, but encrypted.

Thanks in advance!


Solution

  • The keychain (consider the name) is designed to hold keys and other reasonably small secure items. For data, encrypt it with AES using Common Crypto and save the key in the keychain. Create the key from random bytes. Save the encrypted data in the Documents directory or subdirectory.