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 ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.