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.
Namespace:
Rebex.Security.Cryptography
Assembly:
Rebex.Common (in Rebex.Common.dll)
Syntax
Visual Basic |
---|
Public Sub Encrypt ( _ nonce As Byte(), _ plaintext As Byte(), _ ciphertext As Byte(), _ authTag As Byte(), _ additionalAuthData As Byte() _ ) |
C# |
---|
public void Encrypt( byte[] nonce, byte[] plaintext, byte[] ciphertext, byte[] authTag, byte[] additionalAuthData ) |
Parameters
- nonce
- Type: array<System..::..Byte>[]()[][]
The 12-byte nonce.
- plaintext
- Type: array<System..::..Byte>[]()[][]
The byte array that contains plain text that will be encrypted.
- ciphertext
- Type: array<System..::..Byte>[]()[][]
The byte array in which the resulting cipher text will be stored.
- authTag
- Type: array<System..::..Byte>[]()[][]
The 16-byte array in which generated authentication tag will be stored.
- additionalAuthData
- Type: array<System..::..Byte>[]()[][]
Optional (can be null) byte array that contains additional authenticated data (AAD). Same additional authenticated data must be provided when ciphertext is decrypted.
Examples
Copy Code | |
---|---|
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. } |