Retrieves the data and/or attributes stored in the given keychain item.
SDK
- macOS 10.2+
Framework
- Security
Declaration
OSStatus SecKeychainItemCopyAttributesAndData(Sec Keychain Item Ref itemRef, Sec Keychain Attribute Info *info, Sec Item Class *itemClass, Sec Keychain Attribute List * _Nullable *attrList, UInt32 *length, void * _Nullable *outData);
Parameters
itemRef
A reference to the keychain item from which you wish to retrieve data or attributes.
info
A pointer to a list of tags and formats of attributes to retrieve. You can call
Sec
to obtain a list of all possible attribute tags and formats for the item's class. PassKeychain Attribute Info For Item ID NULL
if you don’t wish to retrieve any attributes.itemClass
On return, the item’s class. Pass
NULL
if not required. SeeSec
for valid constants.Item Class attrList
On return, the retrieved attributes and their values . Pass
NULL
if not required. You must call the functionSec
when you no longer need the attributes and values.Keychain Item Free Attributes And Data length
On return, the actual length of the data returned in the
out
parameter.Data outData
On return, the data in this item. Pass
NULL
if not required. You must call the functionSec
when you no longer need the data.Keychain Item Free Attributes And Data
Return Value
A result code. See Security Framework Result Codes.
Discussion
This function returns the data and attributes of a specific keychain item.
Note
This is a CSSM-based API. CSSM is deprecated.
For new development, where possible, you should generally use Sec
to obtain attributes of keychain items instead, because that function is based on Core Foundation types.
You can use the Sec
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 Sec
or Sec
function.
You should pair the Sec
function with the Sec
function, as these functions handle more attributes than are support by the old Keychain Manager and passing them into older calls yields an invalid attribute error. Use the functions Sec
and Sec
when dealing with older Keychain Manager functions.
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 err
result code.