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

# Keychains

Create and manage entire keychains in macOS.

## Discussion

In iOS, apps have access to a single keychain (which logically encompasses the iCloud keychain). This keychain is automatically unlocked when the user unlocks the device and then locked when the device is locked. An app can access only its own keychain items, or those shared with a group to which the app belongs. It can’t manage the keychain container itself.

In macOS, however, the system supports an arbitrary number of keychains. You typically rely on the user to manage these with the Keychain Access app and work implicitly with the default keychain, much as you would in iOS. Nevertheless, the keychain services API does provide functions that you can use to manipulate keychains directly. For example, you can create and manage a keychain that is private to your app. On the other hand, robust access control mechanisms typically make this unnecessary for anything other than an app trying to replicate the keychain access utility.

## Topics

### Creation and Deletion

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

Creates an empty keychain.

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

Deletes one or more keychains from the default keychain search list, and removes the keychain itself if it is a file.

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

An opaque type that represents a keychain.

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

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

### Locking and Unlocking

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

Locks a keychain.

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

Locks all keychains belonging to the current user.

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

Unlocks a keychain.

### Settings

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

Changes the settings of a keychain.

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

Obtains a keychain’s settings.

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

A structure that contains information about keychain settings.

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

Defines the keychain settings version.

### Keychain Management

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

Determines the version of keychain services installed on the user’s system.

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

Opens a keychain.

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

Sets the default keychain.

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

Retrieves a pointer to the default keychain.

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

Determines the path of a keychain.

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

Retrieves status information of a keychain.

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

A value that defines the current status of a keychain.

[SecKeychainStatus Values](/documentation/Security/SecKeychainStatus-values)

Valid values for the keychain status type.

### Search

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

Specifies the list of keychains to use in the default keychain search list.

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

Retrieves a keychain search list.

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

An opaque type that contains information about a keychain search.

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

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

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

Creates a search object matching a list of zero or more attributes.

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

Finds the next keychain item matching the given search criteria.

### User Interaction

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

Enables or disables the user interface for keychain services functions that automatically display a user interface.

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

Indicates whether keychain services functions that normally display a user interaction are allowed to do so.

### Callbacks

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

Registers your keychain event callback function.

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

Unregisters your keychain event callback function.

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

A customized callback function that keychain services call when a keychain event has occurred.

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

Information about a keychain event that keychain services deliver to your app via a callback function.

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

The list of keychain events that can trigger a callback.

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

Bit masks corresponding to the events that can trigger a keychain callback.

### Preference Domains

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

Gets the current keychain preference domain.

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

Sets the keychain preference domain.

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

Retrieves the default keychain from a specified preference domain.

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

Sets the default keychain for a specified preference domain.

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

Retrieves the keychain search list for a specified preference domain.

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

Sets the keychain search list for a specified preference domain.

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

The keychain preference domains.

### Access

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

Sets the application access for a keychain.

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

Retrieves the application access of a keychain.

### Legacy Symbols

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

Returns the CSSM CSP handle for the given keychain object.

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

Returns the CSSM database handle for a given keychain object.

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

Returns the CSSM database handle for a given keychain item object.

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

Returns a CSSM unique record for the given keychain item object.



---

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)