Getting Specific Keychains

As an argument to many of the keychain functions, you can specify a particular keychain. Usually, you will simply use the user’s default keychain. For all of these functions, if you just supply NULL as the keychain, it will use the default keychain. However, if you want to explicitly get the default keychain you use:

OSStatus SecKeychainCopyDefault (SecKeychainRef *keychain)

If you wanted to specify a different keychain (remember that a keychain is just a file), you could use:

OSStatus SecKeychainOpen (const char *pathName, 
                          SecKeychainRef *keychain)

When you are done with a keychain, make sure that you call CFRelease() to free it.

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.