Keychain items
Embed confidential information in items that you store in a keychain.
Overview
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.
[Image]
Topics
Essentials
Using the keychain to manage user secretsTN3137: On Mac keychain APIs and implementationsSecKeychainItemSecKeychainItemGetTypeID()
Adding keychain items
Adding a password to the keychainSecItemAdd(_:_:)Item class keys and valuesItem attribute keys and values
Keychain item search
Searching for keychain itemsSecItemCopyMatching(_:_:)Search attribute keys and valuesItem return result keys
Keychain item modification
Keychain item access
Sharing access to keychain items among a collection of appsKeychain Access Groups EntitlementRestricting keychain item accessibilitySecAccessControlCreateWithFlags(_:_:_:_:)SecAccessControlCreateFlagsSecAccessControlSecAccessControlGetTypeID()
Import and export
SecItemImport(_:_:_:_:_:_:_:_:)SecItemExport(_:_:_:_:_:)SecExternalFormatSecExternalItemTypeSecItemImportExportFlagsSecItemImportExportKeyParametersSecKeyImportExportFlagsSEC_KEY_IMPORT_EXPORT_PARAMS_VERSIONSecKeyImportExportParameters
Legacy keychain item creation
SecKeychainItemCreateFromContent(_:_:_:_:_:_:_:)SecKeychainItemCreateCopy(_:_:_:_:)SecKeychainItemCreatePersistentReference(_:_:)SecKeychainItemCopyFromPersistentReference(_:_:)SecItemClass
Legacy keychain item management
SecKeychainItemCopyAttributesAndData(_:_:_:_:_:_:)SecKeychainItemModifyAttributesAndData(_:_:_:_:)SecKeychainItemFreeAttributesAndData(_:_:)SecKeychainItemCopyContent(_:_:_:_:_:)SecKeychainItemModifyContent(_:_:_:_:)SecKeychainItemFreeContent(_:_:)SecKeychainItemCopyKeychain(_:_:)SecKeychainItemDelete(_:)SecKeychainAttrTypeSecKeychainAttributeSecKeychainAttributePtrSecKeychainAttributeList
Legacy attribute info
SecKeychainAttributeInfoForItemID(_:_:_:)SecKeychainFreeAttributeInfo(_:)SecKeychainAttributeInfoSecItemAttrKeychain Item Attribute Constants For KeysSecAFPServerSignature