Function

SecKeychainItemCreateFromContent

Creates a new keychain item from the supplied parameters.

Declaration

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

Parameters

itemClass

A constant identifying the class of item to create. See SecItemClass for valid constants.

attrList

A pointer to the list of attributes for the item to create.

length

The length of the buffer pointed to by the data parameter.

data

A pointer to a buffer containing the data to store.

keychainRef

A reference to the keychain in which to add the item. Pass NULL to specify the default keychain.

initialAccess

An access object for this keychain item. Use the SecAccessCreate function to create an access object or the SecKeychainItemCopyAccess function to copy an access object from another keychain item. If you pass NULL for this parameter, the access defaults to the application creating the item.

itemRef

On return, a pointer to a reference to the newly created keychain item. This parameter is optional. You must call the CFRelease function to release this object when you are finished using it.

Return Value

Discussion

Each item stored in the keychain contains data (such as a certificate), which is indexed by the item’s attributes. Use this function to create a keychain item from its attributes and data. To create keychain items that hold passwords, use the SecKeychainAddInternetPassword or SecKeychainAddGenericPassword functions.

A SecKeychainItemRef object for a certificate that is stored in a keychain can be safely cast to a SecCertificateRef for use with the Certificate, Key, and Trust API.

This function automatically calls the function SecKeychainUnlock to display the Unlock Keychain dialog box if the keychain is currently locked.

See Also

Legacy Keychain Item Creation

SecKeychainItemCreateCopy

Copies a keychain item from one keychain to another.

SecKeychainItemCreatePersistentReference

Creates a persistent reference for a keychain item.

SecKeychainItemCopyFromPersistentReference

Provides a keychain item reference, given a persistent reference.

SecItemClass

Specifies a keychain item’s class code.