Add more tests for SubtleCrypto::importKey and SubtleCrypto::exportKey
[WebKit-https.git] / LayoutTests / crypto / subtle / aes-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 AES-CBC key with legnth 128 and then export it in raw 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("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>