diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-01-05 20:42:30 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-05 20:42:30 +0530 |
commit | c74eb7a889322e88173cb044a670602d124fcc67 (patch) | |
tree | b5502919639a3f1b6285e8c44dcb4e0465d530f1 /cli | |
parent | 9778545048a9908f62c24b93ae3ec0762e3db2d9 (diff) |
feat(ext/crypto): implement AES-GCM encryption (#13119)
Diffstat (limited to 'cli')
-rw-r--r-- | cli/tests/unit/webcrypto_test.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index 8b5ce55e8..926ed6b6c 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -1418,6 +1418,34 @@ Deno.test(async function testImportEcSpkiPkcs8() { } }); +Deno.test(async function testAesGcmEncrypt() { + const key = await crypto.subtle.importKey( + "raw", + new Uint8Array(16), + { name: "AES-GCM", length: 256 }, + true, + ["encrypt", "decrypt"], + ); + + // deno-fmt-ignore + const iv = new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11]); + const data = new Uint8Array([1, 2, 3]); + + const cipherText = await crypto.subtle.encrypt( + { name: "AES-GCM", iv, additionalData: new Uint8Array() }, + key, + data, + ); + + assert(cipherText instanceof ArrayBuffer); + assertEquals(cipherText.byteLength, 19); + assertEquals( + new Uint8Array(cipherText), + // deno-fmt-ignore + new Uint8Array([50,223,112,178,166,156,255,110,125,138,95,141,82,47,14,164,134,247,22]), + ); +}); + async function roundTripSecretJwk( jwk: JsonWebKey, algId: AlgorithmIdentifier | HmacImportParams, |