diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2021-12-05 09:25:11 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-05 04:55:11 +0100 |
commit | d31378726e78490e88b8a9ec3001b86ea009d978 (patch) | |
tree | bfe465d848b862f8144288419028f16e8fe88ecf /cli/tests | |
parent | c59f90d01f06f995e335c6de76aab0b9ba2c98e5 (diff) |
feat(ext/crypto): implement unwrapKey (#12539)
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/unit/webcrypto_test.ts | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index 5087c7076..0660d9a7e 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -691,6 +691,60 @@ Deno.test(async function testAesKeyGen() { assertEquals(algorithm.length, 256); }); +Deno.test(async function testUnwrapKey() { + const subtle = crypto.subtle; + + const AES_KEY: AesKeyAlgorithm & AesCbcParams = { + name: "AES-CBC", + length: 128, + iv: new Uint8Array(16), + }; + + const RSA_KEY: RsaHashedKeyGenParams & RsaOaepParams = { + name: "RSA-OAEP", + modulusLength: 2048, + publicExponent: new Uint8Array([1, 0, 1]), + hash: "SHA-1", + }; + + const aesKey = await subtle.generateKey(AES_KEY, true, [ + "encrypt", + "decrypt", + ]); + + const rsaKeyPair = await subtle.generateKey( + { + name: "RSA-OAEP", + hash: "SHA-1", + publicExponent: new Uint8Array([1, 0, 1]), + modulusLength: 2048, + }, + false, + ["wrapKey", "encrypt", "unwrapKey", "decrypt"], + ); + + const enc = await subtle.wrapKey( + "raw", + aesKey, + rsaKeyPair.publicKey, + RSA_KEY, + ); + const unwrappedKey = await subtle.unwrapKey( + "raw", + enc, + rsaKeyPair.privateKey, + RSA_KEY, + AES_KEY, + false, + ["encrypt", "decrypt"], + ); + + assert(unwrappedKey instanceof CryptoKey); + assertEquals(unwrappedKey.type, "secret"); + assertEquals(unwrappedKey.extractable, false); + assertEquals(unwrappedKey.usages, ["encrypt", "decrypt"]); +}); + Deno.test(async function testDecryptWithInvalidIntializationVector() { const data = new Uint8Array([42, 42, 42, 42]); const key = await crypto.subtle.generateKey( |