<!--
{
  "availability" : [
    "macOS: 10.7.0 - 12.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Security",
  "identifier" : "/documentation/Security/SecKeyGeneratePairAsync(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Security"
    ],
    "preciseIdentifier" : "c:@F@SecKeyGeneratePairAsync"
  },
  "title" : "SecKeyGeneratePairAsync(_:_:_:)"
}
-->

# SecKeyGeneratePairAsync(_:_:_:)

Generates a public/private key pair.

```
func SecKeyGeneratePairAsync(_ parameters: CFDictionary, _ deliveryQueue: dispatch_queue_t, _ result: @escaping SecKeyGeneratePairBlock)
```

## Parameters

`parameters`

A key generation parameter dictionary. At minimum, this must contain [`kSecAttrKeyType`](/documentation/Security/kSecAttrKeyType) and [`kSecAttrKeySizeInBits`](/documentation/Security/kSecAttrKeySizeInBits). In addition, this function assumes default values for the following keys:

- [`kSecAttrLabel`](/documentation/Security/kSecAttrLabel) defaults to `NULL`.
- [`kSecAttrIsPermanent`](/documentation/Security/kSecAttrIsPermanent) if this key is present and has a value of <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanTrue>, the key or key pair will be added to the default keychain.
- [`kSecAttrApplicationTag`](/documentation/Security/kSecAttrApplicationTag) defaults to `NULL`.
- [`kSecAttrEffectiveKeySize`](/documentation/Security/kSecAttrEffectiveKeySize) defaults to `NULL`, which means the effective key size is the same as the key size ([`kSecAttrKeySizeInBits`](/documentation/Security/kSecAttrKeySizeInBits)).
- [`kSecAttrCanEncrypt`](/documentation/Security/kSecAttrCanEncrypt) defaults to <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanFalse> for private keys, <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanTrue> for public keys.
- [`kSecAttrCanDecrypt`](/documentation/Security/kSecAttrCanDecrypt) defaults to <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanTrue> for private keys, <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanFalse> for public keys.
- [`kSecAttrCanDerive`](/documentation/Security/kSecAttrCanDerive) defaults to <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanTrue>.
- [`kSecAttrCanSign`](/documentation/Security/kSecAttrCanSign) defaults to <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanTrue> for private keys, <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanFalse> for public keys.
- [`kSecAttrCanVerify`](/documentation/Security/kSecAttrCanVerify) defaults to <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanFalse> for private keys, <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanTrue> for public keys.
- [`kSecAttrCanWrap`](/documentation/Security/kSecAttrCanWrap) defaults to <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanFalse> for private keys, <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanTrue> for public keys.
- [`kSecAttrCanUnwrap`](/documentation/Security/kSecAttrCanUnwrap) defaults to <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanTrue> for private keys, <doc://com.apple.documentation/documentation/CoreFoundation/kCFBooleanFalse> for public keys.

    These default values can be overridden by adding a value for the associated key in the parameter dictionary.

`deliveryQueue`

The dispatch queue on which the result block should be scheduled.

`result`

A block of type [`SecKeyGeneratePairBlock`](/documentation/Security/SecKeyGeneratePairBlock) that gets called with the result upon completion.

---

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)