Module aes/aes_cbc
source · [−]Expand description
Code related to AES_CBC mode
Functions
sourcedecrypt
decrypt
source(algorithm: Omit<EnforcedAesCbcParams, "name">, key: AesCbcCryptoKey, data: BufferSource): Promise<ArrayBuffer>
(algorithm: Omit<EnforcedAesCbcParams, "name">, key: AesCbcCryptoKey, data: BufferSource): Promise<ArrayBuffer>
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
algorithm: Omit<EnforcedAesCbcParams, "name">
key: AesCbcCryptoKey
data: BufferSource
Returns Promise<ArrayBuffer>
sourceencrypt
encrypt
source(algorithm: Omit<EnforcedAesCbcParams, "name">, key: AesCbcCryptoKey, data: BufferSource): Promise<ArrayBuffer>
(algorithm: Omit<EnforcedAesCbcParams, "name">, key: AesCbcCryptoKey, data: BufferSource): 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
algorithm: Omit<EnforcedAesCbcParams, "name">
key: AesCbcCryptoKey
data: BufferSource
Returns Promise<ArrayBuffer>
sourceexportKey
exportKey
source(format: KeyFormat, key: AesCbcCryptoKey): Promise<ArrayBuffer | JsonWebKey>
(format: KeyFormat, key: AesCbcCryptoKey): Promise<ArrayBuffer | JsonWebKey>
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
format: KeyFormat
key: AesCbcCryptoKey
Returns Promise<ArrayBuffer | JsonWebKey>
sourcegenerateKey
generateKey
source(algorithm?: Omit<EnforcedAesKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<AesCbcProxiedCryptoKey>
(algorithm?: Omit<EnforcedAesKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<AesCbcProxiedCryptoKey>
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>
sourceimportKey
importKey
source(format: KeyFormat, key: BufferSource | JsonWebKey, algorithm: Omit<AesCbcKeyAlgorithm, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<AesCbcProxiedCryptoKey>
(format: KeyFormat, key: BufferSource | JsonWebKey, algorithm: Omit<AesCbcKeyAlgorithm, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): 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>
sourceunwrapKey
unwrapKey
source(format: KeyFormat, wrappedKey: BufferSource, wrappedKeyAlgorithm: EnforcedImportParams, unwrappingKey: AesCbcCryptoKey, unwrappingKeyAlgorithm: Omit<EnforcedAesCbcParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<CryptoKey>
(format: KeyFormat, wrappedKey: BufferSource, wrappedKeyAlgorithm: EnforcedImportParams, unwrappingKey: AesCbcCryptoKey, unwrappingKeyAlgorithm: Omit<EnforcedAesCbcParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<CryptoKey>
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
format: KeyFormat
wrappedKey: BufferSource
wrappedKeyAlgorithm: EnforcedImportParams
unwrappingKey: AesCbcCryptoKey
unwrappingKeyAlgorithm: Omit<EnforcedAesCbcParams, "name">
extractable: boolean = true
Optional keyUsages: KeyUsage[]
Returns Promise<CryptoKey>
sourcewrapKey
wrapKey
source(format: KeyFormat, key: CryptoKey, wrappingkey: AesCbcCryptoKey, wrapAlgorithm: Omit<EnforcedAesCbcParams, "name">): Promise<ArrayBuffer>
(format: KeyFormat, key: CryptoKey, wrappingkey: AesCbcCryptoKey, wrapAlgorithm: Omit<EnforcedAesCbcParams, "name">): Promise<ArrayBuffer>
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
format: KeyFormat
key: CryptoKey
wrappingkey: AesCbcCryptoKey
wrapAlgorithm: Omit<EnforcedAesCbcParams, "name">