circu.js
    Preparing search index...
    • Encrypt data using AES-GCM with optional AAD (Additional Authenticated Data)

      Parameters

      • key: ArrayBuffer | Uint8Array<ArrayBufferLike>

        Encryption key (16/24/32 bytes for AES-128/192/256)

      • iv: ArrayBuffer | Uint8Array<ArrayBufferLike>

        Initialization vector (recommended 12 bytes)

      • plaintext: ArrayBuffer | Uint8Array<ArrayBufferLike>

        Data to encrypt

      • Optionalaad: ArrayBuffer | Uint8Array<ArrayBufferLike>

        Optional additional authenticated data (authenticated but not encrypted)

      • OptionaltagLength: number

        Optional authentication tag length in bytes (default: 16, range: 4-16)

      Returns GcmEncryptResult

      Object containing ciphertext and authentication tag

      const crypto = import.meta.use('crypto');

      const key = crypto.randomBytes(32); // AES-256
      const iv = crypto.randomBytes(12); // 12 bytes IV for GCM
      const plaintext = new TextEncoder().encode('Hello, World!');
      const aad = new TextEncoder().encode('Additional authenticated data');

      // Without AAD
      const encrypted1 = crypto.gcmEncrypt(key, iv, plaintext);

      // With AAD
      const encrypted2 = crypto.gcmEncrypt(key, iv, plaintext, aad);

      // With custom tag length
      const encrypted3 = crypto.gcmEncrypt(key, iv, plaintext, aad, 12);