ChaCha20Poly1305.Encrypt Method
Namespace: Rebex.Security.Cryptography
Assembly: Rebex.Security.dll (version 7.0.9119)
Encrypt(Byte[], Byte[], Byte[], Byte[], Byte[])
Encrypts plaintext
using the secret key and nonce
, stores the result to the ciphertext
and
authenticates resulting ciphertext
with optional additionalAuthData
and stores the authentication tag to the authTag
.
Declaration
public void Encrypt(byte[] nonce, byte[] plaintext, byte[] ciphertext, byte[] authTag, byte[] additionalAuthData = null)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | nonce | The 12-byte nonce. |
Byte[] | plaintext | The byte array that contains plain text that will be encrypted. |
Byte[] | ciphertext | The byte array in which the resulting cipher text will be stored. |
Byte[] | authTag | The 16-byte array in which generated authentication tag will be stored. |
Byte[] | additionalAuthData | Optional (can be null) byte array that contains additional authenticated data (AAD).
Same additional authenticated data must be provided when |
Examples
using (var chacha20Poly1305 = new ChaCha20Poly1305(key))
{
//Encrypt data.
chacha20Poly1305.Encrypt(nonce, plainText, cipherText, authTag, aaaData);
//After a successful call cipherText contains encrypted data and authTag contains authentication tag.
}