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: CryptoKeyThe AES-GCM
CryptoKeyto decrypt with.data: BufferSourceThe wire-format output from
encryptAesGcm: nonce (12 B) || ciphertext || tag (16 B).options?: AesGcmOptionsOptional 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);