Add more tests for SubtleCrypto::importKey and SubtleCrypto::exportKey
[WebKit-https.git] / LayoutTests / crypto / subtle / aes-import-jwk-key-export-jwk-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 AES-CBC key with legnth 128 and then export it in JWK format");
13
14 jsTestIsAsync = true;
15
16 var jwkKey = {
17     kty: "oct",
18     k: "KbXExKw7lIKkvDHi4ud3lg",
19     alg: "A128CBC",
20     key_ops: ["decrypt", "encrypt", "unwrapKey", "wrapKey"],
21     ext: true,
22 };
23 var extractable = true;
24
25 debug("Importing a key...");
26 crypto.subtle.importKey("jwk", jwkKey, "aes-cbc", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]).then(function(cryptoKey) {
27     debug("Exporting a key...");
28     return crypto.subtle.exportKey("jwk", cryptoKey);
29 }).then(function(result) {
30     exportedJwkKey = result;
31
32     shouldBe("exportedJwkKey.kty", "jwkKey.kty");
33     shouldBe("exportedJwkKey.k", "jwkKey.k");
34     shouldBe("exportedJwkKey.alg", "jwkKey.alg");
35     shouldBe("exportedJwkKey.key_ops", "jwkKey.key_ops");
36     shouldBe("exportedJwkKey.ext", "jwkKey.ext");
37
38     finishJSTest();
39 });
40
41 </script>
42
43 <script src="../../resources/js-test-post.js"></script>
44 </body>
45 </html>