O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Making a New Keychain Item

To create a new keychain item, you use this function:

OSStatus SecKeychainItemCreateFromContent (SecItemClass  itemClass,
                               SecKeychainAttributeList *attrList,
                                                 UInt32  passwdLength, 
                                             const void *password, 
                                         SecKeychainRef  keychainRef,
                                           SecAccessRef  initialAccess,
                                     SecKeychainItemRef *itemRef);

where the itemClass is kSecInternetPasswordItemClass, kSecGenericPasswordItemClass, kSecAppleSharePasswordItemClass, or kSecCertificateItemClass. If you supply NULL as the keychainRef, the item will be added to the default keychain. itemRef will be set to point to the newly created item. To use the default access, just supply NULL as the initialAccess.

As an example, here is a short program that will insert a new item into your default ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required