SecKeyCreateRandomKey(_:_:)
Generates a new public-private key pair.
Declaration
func SecKeyCreateRandomKey(_ parameters: CFDictionary, _ error: UnsafeMutablePointer<Unmanaged<CFError>?>?) -> SecKey?Parameters
- parameters:
A dictionary you use to specify the attributes of the generated keys. See Key Generation Attributes for details.
- error:
An error reference pointer that Seckeycreaterandomkey(_:_:) populates with a suitable error instance on failure.
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.