Function

SecKeychainItemCopyContent

Copies the data and attributes stored in the given keychain item.

Declaration

OSStatus SecKeychainItemCopyContent(SecKeychainItemRef itemRef, SecItemClass *itemClass, SecKeychainAttributeList *attrList, UInt32 *length, void * _Nullable *outData);

Parameters

itemRef

A reference to the keychain item to modify.

itemClass

On return, points to the item’s class. Pass NULL if it is not required. See SecItemClass for valid constants.

attrList

On entry, the list of attributes to get in this item; on return the attributes are filled in. Pass NULL if you don’t need to retrieve any attributes. You must call SecKeychainItemFreeContent when you no longer need the attributes and data.

length

On return, the length of the buffer pointed to by the outData parameter.

outData

On return, a pointer to a buffer containing the data in this item. Pass NULL if you don’t need this data. You must call SecKeychainItemFreeContent when you no longer need the attributes and data.

Return Value

Discussion

This function returns the data and attributes of a specific keychain item.

You can use the SecKeychainSearchCopyNext function to search for a keychain item if you don’t already have the item’s reference object. To find and obtain data from a password keychain item, use the SecKeychainFindInternetPassword or SecKeychainFindGenericPassword function.

You should pair the SecKeychainItemModifyContent function with the SecKeychainItemCopyContent function when dealing with older Keychain Manager functions. The SecKeychainItemCopyAttributesAndData and SecKeychainItemModifyAttributesAndData functions handle more attributes than are supported by the old Keychain Manager; however, passing them into older calls yields an invalid attribute error.

If the keychain item data is encrypted, this function decrypts the data before returning it to you. If the calling application is not in the list of trusted applications, the user is prompted before access is allowed. If the access controls for this item do not allow decryption, the function returns the errSecAuthFailed result code.

See Also

Legacy Keychain Item Management

SecKeychainItemCopyAttributesAndData

Retrieves the data and/or attributes stored in the given keychain item.

SecKeychainItemModifyAttributesAndData

Updates an existing keychain item after changing its attributes or data.

SecKeychainItemFreeAttributesAndData

Releases the memory used by the keychain attribute list and/or the keychain data retrieved in a call to SecKeychainItemCopyAttributesAndData.

SecKeychainItemModifyContent

Updates an existing keychain item after changing its attributes and/or data.

SecKeychainItemFreeContent

Releases the memory used by the keychain attribute list and the keychain data retrieved in a call to the SecKeychainItemCopyContent function.

SecKeychainItemCopyKeychain

Returns the keychain object of a given keychain item.

SecKeychainItemDelete

Deletes a keychain item from the default keychain’s permanent data store.

SecKeychainAttrType

The keychain attribute type.

SecKeychainAttribute

A structure that holds a single keychain attribute.

SecKeychainAttributePtr

A pointer to a keychain attribute structure.

SecKeychainAttributeList

A list of keychain attributes.