Saturday, August 14, 2010

Howto use the Keychain in iPhone SDK to store and retrieve secure Data

This blog post has moved to


  1. Hi
    I am trying to create, store and later retrieve private and public key pair in iPhone. And also create CSR. How can I store it in keychain and later refer to the same key to load?

  2. You could modify the KeyChainItemWrapper so it handles Keys instead of passwords. Replace kSecClassGenericPassword in the code with kSecClassKey. Be aware, that the number of attributes supprted by keys is different from the ones supported by passwords. So you cannot use kSecAttrGeneric to store the key identifier. You might use kSecAttrApplicationLabel. An overview of supported attribute types per keychain item class can be found here:

  3. Hi,

    I am trying to add RSA public key to key chain.But am getting an error while adding


    How can I get rid of this error??


  4. This is great info!
    Thanks a lot for this!


  5. Thank you! I had been searching the internet and read the Apple documentation. I was pretty unclear about the whole thing. Your article helped a lot! Thanks!