Contents

SecKeyCreateRandomKey(_:_:)

Generates a new public-private key pair.

Declaration

func SecKeyCreateRandomKey(_ parameters: CFDictionary, _ error: UnsafeMutablePointer<Unmanaged<CFError>?>?) -> SecKey?

Parameters

Mentioned in

Return Value

The newly generated private key, or NULL on failure. In Objective-C, call the CFRelease function to free the key when you are done with it.

Discussion

To get the associated public key, use SecKeyCopyPublicKey(_:). SecKeyCreateRandomKey(_:_:) fails and returns errSecInteractionNotAllowed if you call it in the background on iPhone or iPad while the device is locked.