Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / crypto / subtle / hmac / import-jwk.html
blobf79bf41f779985a185b7fa337493c95220063cc6
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 <script src="../resources/common.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
11 <script>
12 description("Test importing a JWK key for HMAC.");
14 jsTestIsAsync = true;
16 var nonExtractable = false;
17 var extractable = true;
19 var hmacKey = {
20 "kty": "oct",
21 "alg": "HS256",
22 "use": "sig",
23 "ext": false,
24 "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs"
27 debug("Importing a key...\n");
28 crypto.subtle.importKey("jwk", hmacKey, {name: "HMAC", hash: {name: "SHA-256"}}, nonExtractable, ["sign", "verify"]).then(function(result) {
29 key = result;
31 shouldBe("key.type", "'secret'");
32 shouldBe("key.extractable", "false");
33 shouldBe("key.algorithm.name", "'HMAC'");
34 shouldBe("key.algorithm.length", "256");
35 shouldBe("key.usages", '["sign", "verify"]');
37 debug("\nUsing the key to sign message 'foo'...");
38 return crypto.subtle.sign(key.algorithm, key, asciiToUint8Array('foo'));
39 }).then(function(result) {
40 signature = result;
41 shouldBe("bytesToHexString(new Uint8Array(signature))", "'e03736fe098892b2a2da77812431f7c014d32e2fd69f3bcff883ac923a8fa2da'");
43 debug("\nVerifying the signature...");
44 return crypto.subtle.verify(key.algorithm, key, result, asciiToUint8Array('foo'));
45 }).then(function(result) {
46 verificationResult = result;
47 shouldBe("verificationResult", "true");
48 }).then(finishJSTest, failAndFinishJSTest);
49 </script>
51 </body>
52 </html>