---
title: "SecKeyDecrypt(_:_:_:_:_:_:)"
framework: security
role: symbol
role_heading: Function
path: "security/seckeydecrypt(_:_:_:_:_:_:)"
---

# SecKeyDecrypt(_:_:_:_:_:_:)

Decrypts a block of ciphertext.

## Declaration

```swift
func SecKeyDecrypt(_ key: SecKey, _ padding: SecPadding, _ cipherText: UnsafePointer<UInt8>, _ cipherTextLen: Int, _ plainText: UnsafeMutablePointer<UInt8>, _ plainTextLen: UnsafeMutablePointer<Int>) -> OSStatus
```

## Parameters

- `key`: Private key with which to decrypt the data.
- `padding`: The type of padding used. Possible values are listed in doc://com.apple.security/documentation/Security/SecPadding. Typically, doc://com.apple.security/documentation/Security/SecPadding/PKCS1 is used, which removes PKCS1 padding after decryption. If you specify doc://com.apple.security/documentation/Security/SecPadding/kSecPaddingNone, the decrypted data is returned as-is.
- `cipherText`: The data to decrypt.
- `cipherTextLen`: Length in bytes of the data in the cipherText buffer. This must be less than or equal to the value returned by the doc://com.apple.security/documentation/Security/SecKeyGetBlockSize(_:) function.
- `plainText`: On return, the decrypted text.
- `plainTextLen`: On entry, the size of the buffer provided in the plainText parameter. On return, the amount of data actually placed in the buffer.

## Return Value

Return Value A result code. See Security Framework Result Codes.

## Discussion

Discussion The input buffer (cipherText) can be the same as the output buffer (plainText) to reduce the amount of memory used by the function.
