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