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


func SecKeychainItemModifyContent(_ itemRef: SecKeychainItem, _ attrList: UnsafePointer<SecKeychainAttributeList>?, _ length: UInt32, _ data: UnsafeRawPointer?) -> OSStatus



A reference to the keychain item to modify.


A pointer to the list of attributes to set and their new values. Pass NULL if you have no need to modify attributes.


The length of the buffer pointed to by the data parameter. Pass 0 if you pass NULL in the data parameter.


A pointer to a buffer containing the data to store. Pass NULL if you do not need to modify the data.

Return Value


The keychain item is written to the keychain’s permanent data store.

If the keychain item has not previously been added to a keychain, a call to this function does nothing and returns noErr.

Note that when you use this function to modify a keychain item, Keychain Services updates the modification date of the item. Therefore, you cannot use this function to modify the modification date, as the value you specify will be overwritten with the current time. If you want to change the modification date to something other than the current time, use a CSSM function to do so.

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 support by the old Keychain Manager; however, passing them into older calls yields an invalid attribute error.

See Also

Legacy Keychain Item Management

func SecKeychainItemFreeAttributesAndData(UnsafeMutablePointer<SecKeychainAttributeList>?, UnsafeMutableRawPointer?) -> OSStatus

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

func SecKeychainItemFreeContent(UnsafeMutablePointer<SecKeychainAttributeList>?, UnsafeMutableRawPointer?) -> OSStatus

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

func SecKeychainItemDelete(SecKeychainItem) -> OSStatus

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

typealias SecKeychainAttrType

The keychain attribute type.

struct SecKeychainAttribute

A structure that holds a single keychain attribute.

typealias SecKeychainAttributePtr

A pointer to a keychain attribute structure.

struct SecKeychainAttributeList

A list of keychain attributes.