SecKeyEncrypt(_:_:_:_:_:_:)
Encrypts a block of plaintext.
Declaration
func SecKeyEncrypt(_ key: SecKey, _ padding: SecPadding, _ plainText: UnsafePointer<UInt8>, _ plainTextLen: Int, _ cipherText: UnsafeMutablePointer<UInt8>, _ cipherTextLen: UnsafeMutablePointer<Int>) -> OSStatusParameters
- key:
Public key with which to encrypt the data.
- padding:
The type of padding to use. Possible values are listed in Secpadding. Typically, Pkcs1 is used, which adds PKCS1 padding before encryption. If you specify Ksecpaddingnone, the data is encrypted as-is.
- plainText:
The data to encrypt.
- plainTextLen:
Length in bytes of the data in the
plainTextbuffer. This must be less than or equal to the value returned by the Seckeygetblocksize(_:) function. When PKCS1 padding is performed, the maximum length of data that can be encrypted is 11 bytes less than the value returned by the Seckeygetblocksize(_:) function (secKeyGetBlockSize() - 11). - cipherText:
On return, the encrypted text.
- cipherTextLen:
On entry, the size of the buffer provided in the
cipherTextparameter. On return, the amount of data actually placed in the buffer.
Return Value
A result code. See Security Framework Result Codes.
Discussion
The input buffer (plainText) can be the same as the output buffer (cipherText) to reduce the amount of memory used by the function.