Decrypts ciphertext using the secret key and nonce, stores the result to the ciphertext
and validates authTag.
Namespace:
Rebex.Security.Cryptography
Assembly:
Rebex.Common (in Rebex.Common.dll)
Syntax
Visual Basic |
---|
Public Sub Decrypt ( _ nonce As Byte(), _ ciphertext As Byte(), _ authTag As Byte(), _ plaintext As Byte(), _ additionalAuthData As Byte() _ ) |
C# |
---|
public void Decrypt( byte[] nonce, byte[] ciphertext, byte[] authTag, byte[] plaintext, byte[] additionalAuthData ) |
Parameters
- nonce
- Type: array<System..::..Byte>[]()[][]
The 12-byte nonce.
- ciphertext
- Type: array<System..::..Byte>[]()[][]
The byte array that contains cipher text that will be decrypted.
- authTag
- Type: array<System..::..Byte>[]()[][]
The 16-byte array that contains authentication tag.
- plaintext
- Type: array<System..::..Byte>[]()[][]
The byte array in which the resulting plain text will be stored.
- additionalAuthData
- Type: array<System..::..Byte>[]()[][]
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
Copy Code | |
---|---|
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. } |