Function

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.

Return Value

The encrypted data or nil on failure.

Discussion

You can decrypt this data with the corresponding private key and a call to SecKeyCreateDecryptedData(_:_:_:_:).

See Also

Encryption

Using Keys for Encryption

Perform asymmetric and symmetric encryption and decryption using cryptographic keys.

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