Add more tests for SubtleCrypto::importKey and SubtleCrypto::exportKey
[WebKit-https.git] / LayoutTests / crypto / subtle / hmac-import-jwk-key-export-raw-key.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test-pre.js"></script>
5 <script src="../resources/common.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
10
11 <script>
12 description("Test importing a JWK HMAC key with SHA-1 and then export it in raw format");
13
14 jsTestIsAsync = true;
15
16 var jwkKey = {
17     kty: "oct",
18     k: "vgJ5AXWT3Fm2w_zZCRF4UVwo53rIhwqLm6b9Tq4m1c53dr94eqPlxt99yb9RCjCFDa2C56K448xe4V964xFucg",
19     alg: "HS1",
20     key_ops: ["sign", "verify"],
21     ext: true,
22 };
23 var extractable = true;
24
25 debug("Importing a key...");
26 crypto.subtle.importKey("jwk", jwkKey, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"]).then(function(cryptoKey) {
27     debug("Exporting a key...");
28     return crypto.subtle.exportKey("raw", cryptoKey);
29 }).then(function(result) {
30     exportedRawKey = new Uint8Array(result);
31
32     shouldBe("Base64URL.stringify(exportedRawKey)", "jwkKey.k");
33
34     finishJSTest();
35 });
36
37 </script>
38
39 <script src="../../resources/js-test-post.js"></script>
40 </body>
41 </html>