decryptAesGcm

import { decryptAesGcm } from "jsr:@ende/crypto";

function

async function decryptAesGcm(key: CryptoKey, data: BufferSource, options?: AesGcmOptions): Promise<Uint8Array_>

Decrypts data produced by encryptAesGcm.

Expects input in the format nonce (12 bytes) || ciphertext || tag (16 bytes).

key: CryptoKey

The AES-GCM CryptoKey to decrypt with.

data: BufferSource

The wire-format output from encryptAesGcm: nonce (12 B) || ciphertext || tag (16 B).

options?: AesGcmOptions

Optional additional authenticated data (must match what was used during encryption).

Returns

The decrypted plaintext.

Example: Usage

import { decryptAesGcm, encryptAesGcm } from "@ende/crypto/aes-gcm";
import { assertEquals } from "@ende/assert";

const key = await crypto.subtle.generateKey(
  { name: "AES-GCM", length: 256 },
  false,
  ["encrypt", "decrypt"],
);

const plaintext = new TextEncoder().encode("hello world");
const encrypted = await encryptAesGcm(key, plaintext);

assertEquals(await decryptAesGcm(key, encrypted), plaintext);

Source