Expand description

Code related to AES_GCM mode

Functions

Decrypt with an AES_GCM key

example
const key = await AES_GCM.generateKey();
const data = await AES_GCM.decrypt({iv}, key.self, data);
example
const key = await AES_GCM.generateKey();
const data = await key.decrypt({iv}, data);

Parameters

Returns Promise<ArrayBuffer>

Encrypt with an AES_GCM key

example
const iv = await Random.IV.generate();
const key = await AES_GCM.generateKey();
const message = new TextEncoder().encode("a message");
const data = await AES_GCM.encrypt({iv}, key.self, message);
example
const iv = await Random.IV.generate();
const key = await AES_GCM.generateKey();
const message = new TextEncoder().encode("a message");
const data = await key.encrypt({iv}, message);

Parameters

Returns Promise<ArrayBuffer>

Export an AES_GCM key into the specified format

example
const key = await AES_GCM.generateKey();
const jwk = await AES_GCM.exportKey("jwk", key.self);
example
const key = await AES_GCM.generateKey();
const jwk = await key.exportKey("jwk");

Parameters

Returns Promise<ArrayBuffer | JsonWebKey>

Generate a new AES_GCM key

example
const key = await AES_GCM.generateKey();

Parameters

  • algorithm: Omit<EnforcedAesKeyGenParams, "name"> = { length: 256, }
  • extractable: boolean = true
  • Optional keyUsages: KeyUsage[]

Returns Promise<AesGcmProxiedCryptoKey>

Import an AES_GCM key from the specified format

example
const key = await AES_GCM.importKey("jwk", jwk, { length: 256 });

Parameters

  • format: KeyFormat
  • key: BufferSource | JsonWebKey
  • algorithm: Omit<AesGcmKeyAlgorithm, "name">
  • Optional extractable: boolean
  • Optional keyUsages: KeyUsage[]

Returns Promise<AesGcmProxiedCryptoKey>

Unwrap a wrapped key using the key encryption key

example
const dek = await AES_GCM.unwrapKey("raw", wrappedKey, {name: "AES_GCM"}, kek, {iv});
example
const dek = await kek.unwrapKey("raw", wrappedKey, {name: "AES_GCM"}, {iv});

Parameters

Returns Promise<CryptoKey>

Wrap another key with an AES_GCM key

example
const iv = await Random.IV.generate();
const kek = await AES_GCM.generateKey({length: 256}, true, ['wrapKey', 'unwrapKey']);
const dek = await AES_GCM.generateKey();
const wrappedKey = await AES_GCM.wrapKey("raw", dek.self, kek.self, {iv});
example
const iv = await Random.IV.generate();
const kek = await AES_GCM.generateKey({length: 256}, true, ['wrapKey', 'unwrapKey']);
const dek = await AES_GCM.generateKey();
const wrappedKey = await kek.wrapKey("raw", dek.self, {iv});

Parameters

Returns Promise<ArrayBuffer>