ChaCha20Poly1305.Decrypt Method
Namespace: Rebex.Security.Cryptography
Assembly: Rebex.Security.dll (version 7.0.9048)
Decrypt(Byte[], Byte[], Byte[], Byte[], Byte[])
Decrypts ciphertext
using the secret key and nonce
, stores the result to the ciphertext
and validates authTag
.
Declaration
public void Decrypt(byte[] nonce, byte[] ciphertext, byte[] authTag, byte[] plaintext, byte[] additionalAuthData = null)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | nonce | The 12-byte nonce. |
Byte[] | ciphertext | The byte array that contains cipher text that will be decrypted. |
Byte[] | authTag | The 16-byte array that contains authentication tag. |
Byte[] | plaintext | The byte array in which the resulting plain text will be stored. |
Byte[] | additionalAuthData | Optional (can be null) byte array that contains additional authenticated data (AAD). This byte array should contain the exactly same additional authenticated data that were provided to previous encryption operation; otherwise decryption fails. |
Remarks
When the validation of the authentication tag check fails, then CryptographicException is thrown and ciphertext
is not decrypted.
Examples
using (var chacha20Poly1305 = new ChaCha20Poly1305(key))
{
//Decrypt data. Use the same nonce, same additional authentication data, and use the authTag from the previous encrypt operation.
chacha20Poly1305.Decrypt(nonce, cipherText, authTag, decryptedData, aaaData);
//After a successful call decryptedData contains decrypted data.
}