Expand description

Code related to AES_CBC mode

Functions

Decrypt data with an AES_CBC key

example
const plaintextBytes = await AES_CBC.decrypt(
{ iv },
key.self,
ciphertextBytes
);
example
const plaintextBytes = await key.decrypt(
{ iv },
ciphertextBytes
);

Parameters

Returns Promise<ArrayBuffer>

Encrypt payload with an AES_CBC key

example
const key = await AES_CBC.generateKey();
const iv = await IV.generate();
const ciphertextBytes = await AES_CBC.encrypt(
{ iv },
key.self,
new TextEncoder().encode('message')
);
example
const key = await AES_CBC.generateKey();
const iv = await IV.generate();
const ciphertextBytes = await key.encrypt(
{ iv },
new TextEncoder().encode('message')
);

Parameters

Returns Promise<ArrayBuffer>

Export an AES_CBC key

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

Parameters

Returns Promise<ArrayBuffer | JsonWebKey>

Generate a new AES_CBC key

example
const key = await AES_CBC.generateKey();

Parameters

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

Returns Promise<AesCbcProxiedCryptoKey>

Import an AES_CBC key

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

Parameters

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

Returns Promise<AesCbcProxiedCryptoKey>

Unwrap a wrapped key using the key encryption key

example
const wrappedKey = await AES_CBC.wrapKey("raw", dek.self, kek.self, {
iv,
});
const unwrappedKey = await AES_CBC.unwrapKey(
"raw",
wrappedKey,
{ name: Alg.Mode.AES_CBC },
kek.self,
{ iv }
);
example
const wrappedKey = await AES_CBC.wrapKey("raw", dek.self, kek.self, {
iv,
});
const unwrappedKey = await kek.unwrapKey(
"raw",
wrappedKey,
{ name: Alg.Mode.AES_CBC },
{ iv }
);

Parameters

Returns Promise<CryptoKey>

Wrap another key with an AES_CBC key

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

Parameters

Returns Promise<ArrayBuffer>