decryptChaCha20 function

Future<Uint8List> decryptChaCha20(
  1. Uint8List key,
  2. Uint8List nonce,
  3. Uint8List ciphertext
)

Implementation

Future<Uint8List> decryptChaCha20(
  Uint8List key,
  Uint8List nonce,
  Uint8List ciphertext,
) async {
  final algorithm = Chacha20(macAlgorithm: MacAlgorithm.empty);
  final skey = SecretKey(key);
  final secretBox = SecretBox(ciphertext, nonce: nonce, mac: Mac.empty);

  final plaintext = await algorithm.decrypt(secretBox, secretKey: skey);

  return Uint8List.fromList(plaintext);
}