SecKeyCreateEncryptedData(_:_:_:_:)
Encrypts a block of data using a public key and specified algorithm.
Declaration
func SecKeyCreateEncryptedData(_ key: SecKey, _ algorithm: SecKeyAlgorithm, _ plaintext: CFData, _ error: UnsafeMutablePointer<Unmanaged<CFError>?>?) -> CFData?Parameters
- key:
The public key to use to perform the encryption.
- algorithm:
The encryption algorithm to use. Use one of the encryption algorithms listed in Seckeyalgorithm. You can use the Seckeyisalgorithmsupported(_:_:_:) function to test that the key is suitable for the algorithm.
- plaintext:
The data to be encrypted.
- error:
The address of a Cferror object. If an error occurs, this is set to point at an error instance that describes the failure.
Mentioned in
Return Value
The encrypted data or NULL on failure. In Objective-C, call the CFRelease function to free the data’s memory when you are done with it.
Discussion
You can decrypt this data with the corresponding private key and a call to SecKeyCreateDecryptedData(_:_:_:_:).