diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2021-10-12 16:09:46 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-12 16:09:46 +0530 |
commit | 58f04d8e4600445fe681e845e06f28095c888379 (patch) | |
tree | c2e06053889d309fc1a7024f9851d56095a9acba /cli/tests/unit/webcrypto_test.ts | |
parent | f332d72f1653ec03b64a80d8d4949dce5564cc99 (diff) |
feat(ext/crypto): implement deriveKey (#12117)
Diffstat (limited to 'cli/tests/unit/webcrypto_test.ts')
-rw-r--r-- | cli/tests/unit/webcrypto_test.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index 420fa2a7f..a6e0f28f8 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -513,6 +513,42 @@ unitTest(async function testHkdfDeriveBits() { assertEquals(result.byteLength, 128 / 8); }); +unitTest(async function testDeriveKey() { + // Test deriveKey + const rawKey = await crypto.getRandomValues(new Uint8Array(16)); + const key = await crypto.subtle.importKey( + "raw", + rawKey, + "PBKDF2", + false, + ["deriveKey", "deriveBits"], + ); + + const salt = await crypto.getRandomValues(new Uint8Array(16)); + const derivedKey = await crypto.subtle.deriveKey( + { + name: "PBKDF2", + salt, + iterations: 1000, + hash: "SHA-256", + }, + key, + { name: "HMAC", hash: "SHA-256" }, + true, + ["sign"], + ); + + assert(derivedKey instanceof CryptoKey); + assertEquals(derivedKey.type, "secret"); + assertEquals(derivedKey.extractable, true); + assertEquals(derivedKey.usages, ["sign"]); + + const algorithm = derivedKey.algorithm as HmacKeyAlgorithm; + assertEquals(algorithm.name, "HMAC"); + assertEquals(algorithm.hash.name, "SHA-256"); + assertEquals(algorithm.length, 256); +}); + unitTest(async function testAesCbcEncryptDecrypt() { const key = await crypto.subtle.generateKey( { name: "AES-CBC", length: 128 }, |