encryptAesGcm static method

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

Criptografa bytes com AES-GCM e retorna um EncryptedPayload.

  • key : 16 bytes (AES-128) ou 32 bytes (AES-256). Padrão: 32 bytes.
  • nonce : 12 bytes. Se omitido, gera um nonce aleatório seguro.
  • aad : dados autenticados mas não cifrados (opcional).
final payload = CryptUtil.encryptAesGcm(dados, key: key);
final plain   = CryptUtil.decryptAesGcm(payload);

Implementation

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