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

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.

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