chaCha20Poly1305Decrypt static method

BuBytes chaCha20Poly1305Decrypt({
  1. required List<int> key,
  2. required List<int> nonce,
  3. required List<int> cipherText,
  4. List<int>? assocData,
})

Decrypt data using the ChaCha20-Poly1305 authenticated encryption algorithm. Requires a key, nonce, ciphertext, and optional associated data.

Implementation

static BuBytes chaCha20Poly1305Decrypt({
  required List<int> key,
  required List<int> nonce,
  required List<int> cipherText,
  List<int>? assocData,
}) {
  return chacha20Poly1305(key, (chacha) {
    final decrypt = chacha.decrypt(
      nonce,
      cipherText,
      associatedData: assocData,
    );

    if (decrypt != null) {
      return decrypt;
    }
    throw CoreErrors.cryptoFailed(
      "chaCha20Poly1305Decrypt",
      reason: "Decryption failed.",
    );
  });
}