4 <script src=
"../../../resources/js-test.js"></script>
5 <script src=
"../resources/common.js"></script>
8 <p id=
"description"></p>
9 <div id=
"console"></div>
12 description("Test exporting an AES key.");
16 var extractable
= true;
17 var nonExtractable
= false;
21 "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs"
24 debug("Importing a JWK key...");
25 crypto
.subtle
.importKey("jwk", jwkKey
, { name
: "HMAC", hash
: {name
: "SHA-256"} }, extractable
, ["sign", "verify"]).then(function(result
) {
28 return crypto
.subtle
.exportKey(null, key
);
29 }).then(failAndFinishJSTest
, function(result
) {
31 return crypto
.subtle
.exportKey(undefined, key
);
32 }).then(failAndFinishJSTest
, function(result
) {
34 return crypto
.subtle
.exportKey({}, key
);
35 }).then(failAndFinishJSTest
, function(result
) {
37 return crypto
.subtle
.exportKey("", key
);
38 }).then(failAndFinishJSTest
, function(result
) {
40 return crypto
.subtle
.exportKey("foobar", key
);
41 }).then(failAndFinishJSTest
, function(result
) {
44 debug("Exporting the key as raw data...");
45 return crypto
.subtle
.exportKey("raw", key
);
46 }, failAndFinishJSTest
).then(function(result
) {
47 exportedData
= result
;
48 shouldBe("bytesToHexString(new Uint8Array(exportedData))", "'6a18e49feff7f3b7e09ec89b7f6deab2f6a18e49feff7f3b7e09ec89b7f6deab'");
50 debug("Exporting the key as JWK...");
51 return crypto
.subtle
.exportKey("jwk", key
);
52 }).then(function(result
) {
54 shouldBe("exportedJWK.kty", "'oct'");
55 shouldBe("exportedJWK.k", "'ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs'");
56 shouldBe("exportedJWK.alg", "'HS256'");
57 shouldBe("exportedJWK.ext", "true");
58 shouldBe("exportedJWK.use", "undefined");
59 shouldBe("exportedJWK.key_ops", "['sign', 'verify']");
61 debug("\nImporting a key that's not extractable...");
62 return crypto
.subtle
.importKey("jwk", jwkKey
, { name
: "HMAC", hash
: {name
: "SHA-256"} }, nonExtractable
, ["sign", "verify"]);
63 }, failAndFinishJSTest
).then(function(result
) {
66 debug("\nTrying to export as raw...");
67 return crypto
.subtle
.exportKey("raw", key
);
68 }).then(function(result
) {
69 testFailed("Promise wasn't rejected");
73 testPassed("Rejected, as expected");
75 debug("Trying to export as jwk...");
76 return crypto
.subtle
.exportKey("jwk", key
);
77 }).then(function(result
) {
78 testFailed("Promise wasn't rejected");
82 testPassed("Rejected, as expected");