<!--
{
  "documentType" : "article",
  "framework" : "Security",
  "identifier" : "/documentation/Security/keychain-items",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Keychain items"
}
-->

# Keychain items

Embed confidential information in items that you store in a keychain.

## Discussion

When you want to store a secret such as a password or cryptographic key, you package it as a keychain item. Along with the data itself, you provide a set of publicly visible attributes both to control the item’s accessibility and to make it searchable. As shown in Figure 1, keychain services handles data encryption and storage (including data attributes) in a keychain, which is an encrypted database stored on disk. Later, authorized processes use keychain services to find the item and decrypt its data.

![Diagram showing data being encrypted and then combined with attributes into a keychain item before being stored in a keychain.](images/com.apple.security/media-2891903@2x.png)

## Topics

### Essentials

[Using the keychain to manage user secrets](/documentation/Security/using-the-keychain-to-manage-user-secrets)

Relieve the user of remembering small secrets by storing them in the keychain.

  <doc://com.apple.documentation/documentation/Technotes/tn3137-on-mac-keychains>

[`SecKeychainItem`](/documentation/Security/SecKeychainItem)

An opaque type that represents a keychain item.

[`SecKeychainItemGetTypeID()`](/documentation/Security/SecKeychainItemGetTypeID())

Returns the unique identifier of the opaque type to which a keychain item object belongs.

### Adding keychain items

[Adding a password to the keychain](/documentation/Security/adding-a-password-to-the-keychain)

Add network credentials to the keychain on behalf of the user.

[`SecItemAdd(_:_:)`](/documentation/Security/SecItemAdd(_:_:))

Adds one or more items to a keychain.

[Item class keys and values](/documentation/Security/item-class-keys-and-values)

Specify the class of a keychain item.

[Item attribute keys and values](/documentation/Security/item-attribute-keys-and-values)

Specify the attributes of keychain items.

### Keychain item search

[Searching for keychain items](/documentation/Security/searching-for-keychain-items)

Find keychain items based on search criteria that you specify.

[`SecItemCopyMatching(_:_:)`](/documentation/Security/SecItemCopyMatching(_:_:))

Returns one or more keychain items that match a search query, or copies attributes of specific keychain items.

[Search attribute keys and values](/documentation/Security/search-attribute-keys-and-values)

Filter a keychain item search.

[Item return result keys](/documentation/Security/item-return-result-keys)

Specify how you want returned keychain item data formatted.

### Keychain item modification

[Updating and deleting keychain items](/documentation/Security/updating-and-deleting-keychain-items)

Modify items in the keychain when the user’s data changes.

[`SecItemUpdate(_:_:)`](/documentation/Security/SecItemUpdate(_:_:))

Modifies items that match a search query.

[`SecItemDelete(_:)`](/documentation/Security/SecItemDelete(_:))

Deletes items that match a search query.

### Keychain item access

[Sharing access to keychain items among a collection of apps](/documentation/Security/sharing-access-to-keychain-items-among-a-collection-of-apps)

Enable apps to share keychain items with each other by adding the apps to an access group.

  <doc://com.apple.documentation/documentation/BundleResources/Entitlements/keychain-access-groups>

[Restricting keychain item accessibility](/documentation/Security/restricting-keychain-item-accessibility)

Set the conditions under which an app can access a keychain item such as a password.

[`SecAccessControlCreateWithFlags(_:_:_:_:)`](/documentation/Security/SecAccessControlCreateWithFlags(_:_:_:_:))

Creates a new access control object with the specified protection type and flags.

[`SecAccessControlCreateFlags`](/documentation/Security/SecAccessControlCreateFlags)

Access control constants that dictate how a keychain item may be used.

[`SecAccessControl`](/documentation/Security/SecAccessControl)

An opaque type that contains information about how a keychain item may be used.

[`SecAccessControlGetTypeID()`](/documentation/Security/SecAccessControlGetTypeID())

Returns the unique identifier of the opaque type to which a keychain item access control object belongs.

### Import and export

[`SecItemImport(_:_:_:_:_:_:_:_:)`](/documentation/Security/SecItemImport(_:_:_:_:_:_:_:_:))

Imports one or more certificates, keys, or identities and optionally adds them to a keychain.

[`SecItemExport(_:_:_:_:_:)`](/documentation/Security/SecItemExport(_:_:_:_:_:))

Exports one or more certificates, keys, or identities.

[`SecExternalFormat`](/documentation/Security/SecExternalFormat)

The external format of a keychain item.

[`SecExternalItemType`](/documentation/Security/SecExternalItemType)

The import item type.

[`SecItemImportExportFlags`](/documentation/Security/SecItemImportExportFlags)

The import and export function flags.

[`SecItemImportExportKeyParameters`](/documentation/Security/SecItemImportExportKeyParameters)

The import/export parameter structure.

[`SecKeyImportExportFlags`](/documentation/Security/SecKeyImportExportFlags)

The import/export parameter structure flags.

[`SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION`](/documentation/Security/SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION)

The import/export parameter structure version.

[`SecKeychainItemImport`](/documentation/Security/SecKeychainItemImport)

Imports one or more certificates, keys, or identities and adds them to a keychain.

[`SecKeychainItemExport`](/documentation/Security/SecKeychainItemExport)

Exports one or more certificates, keys, or identities.

[`SecKeyImportExportParameters`](/documentation/Security/SecKeyImportExportParameters)

The legacy import/export parameter structure.

### Legacy keychain item creation

Use the functions in [Adding keychain items](/documentation/Security/keychain-items#Adding-keychain-items) instead.

[`SecKeychainItemCreateFromContent(_:_:_:_:_:_:_:)`](/documentation/Security/SecKeychainItemCreateFromContent(_:_:_:_:_:_:_:))

Creates a new keychain item from the supplied parameters.

[`SecKeychainItemCreateCopy(_:_:_:_:)`](/documentation/Security/SecKeychainItemCreateCopy(_:_:_:_:))

Copies a keychain item from one keychain to another.

[`SecKeychainItemCreatePersistentReference(_:_:)`](/documentation/Security/SecKeychainItemCreatePersistentReference(_:_:))

Creates a persistent reference for a keychain item.

[`SecKeychainItemCopyFromPersistentReference(_:_:)`](/documentation/Security/SecKeychainItemCopyFromPersistentReference(_:_:))

Provides a keychain item reference, given a persistent reference.

[`SecItemClass`](/documentation/Security/SecItemClass)

Specifies a keychain item’s class code.

### Legacy keychain item management

Use the functions in [Keychain item search](/documentation/Security/keychain-items#Keychain-item-search) instead.

[`SecKeychainItemCopyAttributesAndData(_:_:_:_:_:_:)`](/documentation/Security/SecKeychainItemCopyAttributesAndData(_:_:_:_:_:_:))

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

[`SecKeychainItemModifyAttributesAndData(_:_:_:_:)`](/documentation/Security/SecKeychainItemModifyAttributesAndData(_:_:_:_:))

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

[`SecKeychainItemFreeAttributesAndData(_:_:)`](/documentation/Security/SecKeychainItemFreeAttributesAndData(_:_:))

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

[`SecKeychainItemCopyContent(_:_:_:_:_:)`](/documentation/Security/SecKeychainItemCopyContent(_:_:_:_:_:))

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

[`SecKeychainItemModifyContent(_:_:_:_:)`](/documentation/Security/SecKeychainItemModifyContent(_:_:_:_:))

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

[`SecKeychainItemFreeContent(_:_:)`](/documentation/Security/SecKeychainItemFreeContent(_:_:))

Releases the memory used by the keychain attribute list and the keychain data retrieved in a call to the [`SecKeychainItemCopyContent(_:_:_:_:_:)`](/documentation/Security/SecKeychainItemCopyContent(_:_:_:_:_:)) function.

[`SecKeychainItemCopyKeychain(_:_:)`](/documentation/Security/SecKeychainItemCopyKeychain(_:_:))

Returns the keychain object of a given keychain item.

[`SecKeychainItemDelete(_:)`](/documentation/Security/SecKeychainItemDelete(_:))

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

[`SecKeychainAttrType`](/documentation/Security/SecKeychainAttrType)

The keychain attribute type.

[`SecKeychainAttribute`](/documentation/Security/SecKeychainAttribute)

A structure that holds a single keychain attribute.

[`SecKeychainAttributePtr`](/documentation/Security/SecKeychainAttributePtr)

A pointer to a keychain attribute structure.

[`SecKeychainAttributeList`](/documentation/Security/SecKeychainAttributeList)

A list of keychain attributes.

### Legacy attribute info

Use the functions in [Adding keychain items](/documentation/Security/keychain-items#Adding-keychain-items) and [Keychain item search](/documentation/Security/keychain-items#Keychain-item-search) instead.

[`SecKeychainAttributeInfoForItemID(_:_:_:)`](/documentation/Security/SecKeychainAttributeInfoForItemID(_:_:_:))

Obtains tags for all possible attributes of a given item class.

[`SecKeychainFreeAttributeInfo(_:)`](/documentation/Security/SecKeychainFreeAttributeInfo(_:))

Releases the memory acquired by calling the `SecKeychainAttributeInfoForItemID` function.

[`SecKeychainAttributeInfo`](/documentation/Security/SecKeychainAttributeInfo)

A structure that represents an attribute.

[`SecItemAttr`](/documentation/Security/SecItemAttr)

Specifies a keychain item’s attributes.

[Keychain Item Attribute Constants For Keys](/documentation/Security/keychain-item-attribute-constants-for-keys)

Specifies the attributes for a key item in a keychain.

[`SecAFPServerSignature`](/documentation/Security/SecAFPServerSignature)

Represents a 16-byte Apple File Protocol server signature block.

### Legacy password storage

Use the functions in [Adding keychain items](/documentation/Security/keychain-items#Adding-keychain-items) and [Keychain item search](/documentation/Security/keychain-items#Keychain-item-search) instead.

[`SecKeychainAddInternetPassword(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:)`](/documentation/Security/SecKeychainAddInternetPassword(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:))

Adds a new Internet password to a keychain.

[`SecKeychainFindInternetPassword(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:)`](/documentation/Security/SecKeychainFindInternetPassword(_:_:_:_:_:_:_:_:_:_:_:_:_:_:_:))

Finds the first Internet password based on the attributes passed.

[`SecKeychainAddGenericPassword(_:_:_:_:_:_:_:_:)`](/documentation/Security/SecKeychainAddGenericPassword(_:_:_:_:_:_:_:_:))

Adds a new generic password to a keychain.

[`SecKeychainFindGenericPassword(_:_:_:_:_:_:_:_:)`](/documentation/Security/SecKeychainFindGenericPassword(_:_:_:_:_:_:_:_:))

Finds the first generic password based on the attributes passed.

[`SecProtocolType`](/documentation/Security/SecProtocolType)

The protocol type associated with an Internet password.

[`SecAuthenticationType`](/documentation/Security/SecAuthenticationType)

The authentication type to use for an Internet password.

[`SecPassword`](/documentation/Security/SecPassword)

Contains information about a password.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)