Function

SecKeyCreateRandomKey

Generates a new private/public key pair.

Declaration

SecKeyRef SecKeyCreateRandomKey(CFDictionaryRef parameters, CFErrorRef  _Nullable *error);

Parameters

parameters

A dictionary you use to specify the attributes of the keys to be generated. See Key Generation Attributes for details.

error

An error reference pointer that is populated with a suitable error instance on failure.

Return Value

The newly generated private key or NULL on failure. Call the CFRelease function to free the key when you are done with it.

Discussion

To get the associated public key, use SecKeyCopyPublicKey.

See Also

Key Generation

Generating New Cryptographic Keys

Create both asymmetric and symmetric cryptographic keys.

Storing Keys in the Secure Enclave

Create an extra layer of security for your private keys.

SecKeyCopyPublicKey

Gets the public key associated with the given private key.

Key Generation Attributes

Use attribute dictionary keys during cryptographic key generation.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software