Add more tests for SubtleCrypto::importKey and SubtleCrypto::exportKey
[WebKit-https.git] / LayoutTests / crypto / subtle / rsa-import-jwk-key-export-jwk-key-public.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 RSA-OAEP public key with SHA-1 and then export it in JWK format");
13
14 jsTestIsAsync = true;
15
16 var jwkKey = {
17     kty: "RSA",
18     alg: "RSA-OAEP",
19     key_ops: ["encrypt", "wrapKey"],
20     ext: true,
21     n: "p55Xl-DyqKL06TE8GCuXd_e-ruTqVB19iDH6DwTIknTyM0fl8EY6qsyOBNTxjpLDsOldEJ8QblG78WY7xYTZtNn-fimz5eG80bwSZ6FUO10z3ikeKzPPC7K4AA196rMoiEu2G4mSfqeg5zz6_iqHf8u_md_n8yk_iPaXJ9RVT-W4zEQQ6WSlsOtYa7blSSAlq0JYDJciNeE0RGqUU-UjcxUWIEnT2ODHGRzSfKHgc8O3fGt4dpVm0op1yItBcSAY-0_f1p_YrVDo8bsyq2uodyDGYhcuQgYJ0NjMgT_rb8rUPpR3bUitd-IZJd_NO9i_NmvbnQfgl6kfnxe_2kM4Tw",
22     e: "AQAB"
23 };
24 var extractable = true;
25
26 debug("Importing a key...");
27 crypto.subtle.importKey("jwk", jwkKey, {name: "RSA-OAEP", hash: "sha-1"}, extractable, ["encrypt", "wrapKey"]).then(function(cryptoKey) {
28     debug("Exporting a key...");
29     return crypto.subtle.exportKey("jwk", cryptoKey);
30 }).then(function(result) {
31     exportedJwkKey = result;
32
33     shouldBe("exportedJwkKey.kty", "jwkKey.kty");
34     shouldBe("exportedJwkKey.alg", "jwkKey.alg");
35     shouldBe("exportedJwkKey.key_ops", "jwkKey.key_ops");
36     shouldBe("exportedJwkKey.ext", "jwkKey.ext");
37     shouldBe("exportedJwkKey.n", "jwkKey.n");
38     shouldBe("exportedJwkKey.e", "jwkKey.e");
39
40     finishJSTest();
41 });
42
43 </script>
44
45 <script src="../../resources/js-test-post.js"></script>
46 </body>
47 </html>