encryptBytes static method

EncryptedPayload encryptBytes(
  1. List<int> bytes, {
  2. Uint8List? key,
  3. Uint8List? nonce,
  4. List<int>? aad,
})

Criptografa bytes com ChaCha20-Poly1305 e retorna um EncryptedPayload.

  • key : 32 bytes. Se omitido, gera uma chave aleatória segura.
  • nonce : 12 bytes. Se omitido, gera um nonce aleatório seguro.
  • aad : dados autenticados mas não cifrados (opcional).

Implementation

static EncryptedPayload encryptBytes(
  List<int> bytes, {
  Uint8List? key,
  Uint8List? nonce,
  List<int>? aad,
}) {
  final cipher = ChaCha20Poly1305(
    key: key ?? generateKey(),
    nonce: nonce ?? generateNonce(),
    aad: aad != null ? Uint8List.fromList(aad) : Uint8List(0),
  );
  return cipher.encrypt(bytes);
}