@me2em/crypto
    Preparing search index...

    Function encryptAead

    • Encrypts plaintext with AES-256-GCM using the provided CryptoKey.

      Generates a fresh random IV (12 bytes) for every call — reusing an IV with the same key in GCM mode catastrophically compromises confidentiality.

      The returned ciphertext includes the 16-byte GCM tag as its last 16 bytes; no separate authTag field is needed.

      Parameters

      • key: CryptoKey

        CryptoKey imported via importAeadKey.

      • plaintext: Uint8Array

        The data to encrypt.

      Returns Promise<AeadResult>

      AeadResult with ciphertext (tag included) and IV.

      'ENCRYPTION_FAILED' if WebCrypto encrypt fails.

      const { ciphertext, iv } = await encryptAead(key, secretData);
      // store/transmit ciphertext + iv together