chacha20poly1305 function
Encrypts or Decrypts the message
using ChaCha20 cipher and generates an
authentication tag with Poly1305.
Parameters:
message
: arbitrary length plain-text.key
: Either 16 or 32 bytes key.nonce
: Either 8 or 12 bytes nonce.aad
: Additional authenticated data.counter
: Initial block number.mac
: A 128-bit or 16-bytes long authentication tag for verification.
Throws: AssertionError on mac
verification failure.
Both the encryption and decryption can be done using this same method.
Implementation
AEADResultWithIV chacha20poly1305(
List<int> message,
List<int> key, {
List<int>? mac,
List<int>? nonce,
List<int>? aad,
Nonce64? counter,
}) {
var algo = ChaCha20Poly1305(
key,
nonce: nonce,
counter: counter,
aad: aad,
);
if (mac != null && !algo.verify(message, mac)) {
throw AssertionError('Message authenticity check failed');
}
return algo.sign(message);
}