---
title: "SecItemExport(_:_:_:_:_:)"
framework: security
role: symbol
role_heading: Function
path: "security/secitemexport(_:_:_:_:_:)"
---

# SecItemExport(_:_:_:_:_:)

Exports one or more certificates, keys, or identities.

## Declaration

```swift
func SecItemExport(_ secItemOrArray: CFTypeRef, _ outputFormat: SecExternalFormat, _ flags: SecItemImportExportFlags, _ keyParams: UnsafePointer<SecItemImportExportKeyParameters>?, _ exportedData: UnsafeMutablePointer<CFData?>) -> OSStatus
```

## Parameters

- `secItemOrArray`: The keychain item or items to export. You can export only the following types of keychain items: doc://com.apple.security/documentation/Security/SecCertificate, doc://com.apple.security/documentation/Security/SecKey, and doc://com.apple.security/documentation/Security/SecIdentity. If you are exporting exactly one item, you can specify a doc://com.apple.security/documentation/Security/SecKeychainItem object. Otherwise this parameter is a doc://com.apple.documentation/documentation/CoreFoundation/CFArray object containing a number of items of type doc://com.apple.security/documentation/Security/SecKeychainItem.
- `outputFormat`: The format of the desired external representation for the item. Set this parameter to doc://com.apple.security/documentation/Security/SecExternalFormat/formatUnknown to use the default for that item type. Possible values for this parameter and default values are enumerated in doc://com.apple.security/documentation/Security/SecExternalFormat.
- `flags`: A flag field indicating whether the exported item should have PEM armor. PEM armor refers to a way of expressing binary data as an ASCII string so that it can be transferred over text-only channels such as email. Set this flag to doc://com.apple.security/documentation/Security/SecItemImportExportFlags/pemArmour if you want PEM armoring.
- `keyParams`: A pointer to a structure containing a set of input parameters for the function. If no key items are being exported, these parameters are optional and you can set the keyParams parameter to NULL. For more information, see doc://com.apple.security/documentation/Security/SecItemImportExportKeyParameters.
- `exportedData`: On return, the variable referenced by this argument is overwritten with a doc://com.apple.documentation/documentation/CoreFoundation/CFData object containing the external representation of the keychain item or items. You are responsible for releasing this object by calling doc://com.apple.documentation/documentation/CoreFoundation/CFRelease.

## Return Value

Return Value A result code. See Security Framework Result Codes.

## Discussion

Discussion This function works only with keys, certificates, and identities. An identity is the combination of a certificate and its associated private key. Although public keys are commonly stored in certificates, they can be stored separately in the keychain as well; for example, when you call the SecKeyCreatePair function to create a key pair, both the public and private keys are stored in the keychain. Use the SecKeychainSearchCopyNext function to find a key or certificate. Use the SecIdentitySearchCopyNext function in the Certificate, Key, and Trust API to find an identity.
