views:

12595

answers:

5

This question discusses encrypting data on the iPhone using the crypt() function. As an alternative, is there a keychain on the iPhone and if so, what code would I use to access it in order to store login details and then retrieve them for us in an application?

+13  A: 

There is a keychain you can use - for code, the best bet is to check out the GenericKeychain sample application from Apple:

http://developer.apple.com/iphone/library/samplecode/GenericKeychain/index.html

Adam Byram
Thanks for pointing that out!
maralbjo
+2  A: 

Also remember that when generating an AppID, if you want more than one application to access the same Keychain information, you have to generate a wild card AppID (#####.com.prefix.*)...

whoisjake
+20  A: 

One other thing to note: the keychain APIs don't work in the simulator, only on the device. This could save you a lot of frustration when testing!

Ben Gottlieb
Thank you for this!
Adam Ernst
Thanks for pointing that out!
maralbjo
Thank you for saving me a lot of time.
maclema
+4  A: 

I really like Buzz Anderson's Keychain abstraction layer and I eagerly await Jens Alfke's MYCrypto to reach a usable state. The latter does a competent job of allowing use on Mac OS X and the iPhone using the same code, though its features only mimic a small subset of the Keychain's.

bbrown
+1  A: 

With the latest version 1.2 of the GenericKeychain sample Apple provides a keychain wrapper that also runs on the iPhone Simulator. Check out at this article for details: http://dev-metal.blogspot.com/2010/08/howto-use-keychain-in-iphone-sdk-to.html

alis