Module aes/aes_ctr
source · [−]Expand description
Code related to AES_CTR mode
Functions
sourcedecrypt
decrypt
source(algorithm: Omit<EnforcedAesCtrParams, "name">, key: AesCtrCryptoKey, data: BufferSource): Promise<ArrayBuffer>
(algorithm: Omit<EnforcedAesCtrParams, "name">, key: AesCtrCryptoKey, data: BufferSource): Promise<ArrayBuffer>
Decrypt with an AES_CTR key
example
const data = await AES_CTR.decrypt({length, counter}, key.self, data);
example
const data = await key.decrypt({length, counter}, data);
Parameters
algorithm: Omit<EnforcedAesCtrParams, "name">
key: AesCtrCryptoKey
data: BufferSource
Returns Promise<ArrayBuffer>
sourceencrypt
encrypt
source(algorithm: Omit<EnforcedAesCtrParams, "name">, key: AesCtrCryptoKey, data: BufferSource): Promise<ArrayBuffer>
(algorithm: Omit<EnforcedAesCtrParams, "name">, key: AesCtrCryptoKey, data: BufferSource): Promise<ArrayBuffer>
Encrypt with an AES_CTR key
example
const key = await AES_CTR.generateKey();
const message = new TextEncoder().encode("a message");
const length = 8;
const counter = await AES_CTR.generateCounter(length);
const data = await AES_CTR.encrypt({length, counter}, key.self, message);
example
const key = await AES_CTR.generateKey();
const message = new TextEncoder().encode("a message");
const length = 8;
const counter = await AES_CTR.generateCounter(length);
const data = await key.encrypt({length, counter}, message);
Parameters
algorithm: Omit<EnforcedAesCtrParams, "name">
key: AesCtrCryptoKey
data: BufferSource
Returns Promise<ArrayBuffer>
sourceexportKey
exportKey
source(format: KeyFormat, key: AesCtrCryptoKey): Promise<ArrayBuffer | JsonWebKey>
(format: KeyFormat, key: AesCtrCryptoKey): Promise<ArrayBuffer | JsonWebKey>
Export an AES_CTR key into the specified format
example
const key = await AES_CTR.generateKey();
const jwk = await AES_CTR.exportKey("jwk", key.self);
example
const key = await AES_CTR.generateKey();
const jwk = await key.exportKey("jwk");
Parameters
format: KeyFormat
key: AesCtrCryptoKey
Returns Promise<ArrayBuffer | JsonWebKey>
sourcegenerateKey
generateKey
source(algorithm?: Omit<EnforcedAesKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<AesCtrProxiedCryptoKey>
(algorithm?: Omit<EnforcedAesKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<AesCtrProxiedCryptoKey>
Generate a new AES_CTR key
example
const key = await AES_CTR.generateKey();
Parameters
algorithm: Omit<EnforcedAesKeyGenParams, "name"> = { length: 256, }
extractable: boolean = true
Optional keyUsages: KeyUsage[]
Returns Promise<AesCtrProxiedCryptoKey>
sourceimportKey
importKey
source(format: KeyFormat, key: BufferSource | JsonWebKey, algorithm: Omit<AesCtrKeyAlgorithm, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<AesCtrProxiedCryptoKey>
(format: KeyFormat, key: BufferSource | JsonWebKey, algorithm: Omit<AesCtrKeyAlgorithm, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<AesCtrProxiedCryptoKey>
Import an AES_CTR key from the specified format
example
const key = await AES_CTR.importKey("jwk", jwk, { length: 256 });
Parameters
format: KeyFormat
key: BufferSource | JsonWebKey
algorithm: Omit<AesCtrKeyAlgorithm, "name">
Optional extractable: boolean
Optional keyUsages: KeyUsage[]
Returns Promise<AesCtrProxiedCryptoKey>
sourceunwrapKey
unwrapKey
source(format: KeyFormat, wrappedKey: BufferSource, wrappedKeyAlgorithm: EnforcedImportParams, unwrappingKey: AesCtrCryptoKey, unwrappingKeyAlgorithm: Omit<EnforcedAesCtrParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<CryptoKey>
(format: KeyFormat, wrappedKey: BufferSource, wrappedKeyAlgorithm: EnforcedImportParams, unwrappingKey: AesCtrCryptoKey, unwrappingKeyAlgorithm: Omit<EnforcedAesCtrParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<CryptoKey>
Unwrap a wrapped key using the key encryption key
example
const dek = await AES_CTR.unwrapKey("raw", wrappedKey, {name: "AES_CTR"}, kek.self, {length, counter});
example
const dek = await kek.unwrapKey("raw", wrappedKey, {name: "AES_CTR"}, {length, counter});
Parameters
format: KeyFormat
wrappedKey: BufferSource
wrappedKeyAlgorithm: EnforcedImportParams
unwrappingKey: AesCtrCryptoKey
unwrappingKeyAlgorithm: Omit<EnforcedAesCtrParams, "name">
extractable: boolean = true
Optional keyUsages: KeyUsage[]
Returns Promise<CryptoKey>
sourcewrapKey
wrapKey
source(format: KeyFormat, key: CryptoKey, wrappingkey: AesCtrCryptoKey, wrapAlgorithm: Omit<EnforcedAesCtrParams, "name">): Promise<ArrayBuffer>
(format: KeyFormat, key: CryptoKey, wrappingkey: AesCtrCryptoKey, wrapAlgorithm: Omit<EnforcedAesCtrParams, "name">): Promise<ArrayBuffer>
Wrap another key with an AES_CTR key
example
const kek = await AES_CTR.generateKey({length: 256}, true, ['wrapKey', 'unwrapKey']);
const dek = await AES_CTR.generateKey();
const length = 8;
const counter = await AES_CTR.generateCounter(length);
const wrappedKey = await AES_CTR.wrapKey("raw", dek.self, kek.self, {length, counter});
example
const kek = await AES_CTR.generateKey({length: 256}, true, ['wrapKey', 'unwrapKey']);
const dek = await AES_CTR.generateKey();
const length = 8;
const counter = await AES_CTR.generateCounter(length);
const wrappedKey = await kek.wrapKey("raw", dek.self, {length, counter});
Parameters
format: KeyFormat
key: CryptoKey
wrappingkey: AesCtrCryptoKey
wrapAlgorithm: Omit<EnforcedAesCtrParams, "name">