blob: 11c0ecb52a6817a86430841e1b4f620196dff517 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test generating, importing and exporting keys for AES-KW. Test that they can't be used with another algorithm.");
jsTestIsAsync = true;
var extractable = true;
debug("Generating a key...");
crypto.subtle.generateKey({name: "aes-kw", length: 256}, extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]).then(function(result) {
key = result;
shouldBe("key.toString()", "'[object Key]'");
shouldBe("key.type", "'secret'");
shouldBe("key.algorithm.name", "'AES-KW'");
shouldBe("key.algorithm.length", "256");
debug("\nTesting that the key can't be used with AES-CBC...");
iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f");
shouldThrow('crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, hexStringToUint8Array("00"))');
debug("\nExporting the key to raw...");
return crypto.subtle.exportKey('raw', key);
}).then(function(result) {
exportedKey = result;
shouldBe("exportedKey.toString()", "'[object ArrayBuffer]'");
debug("Importing it back...");
return crypto.subtle.importKey('raw', exportedKey, "aes-kw", extractable, ["encrypt", "decrypt", "wrapKey", "unwrapKey"]);
}).then(function(result) {
importedKey = result;
shouldBe("importedKey.toString()", "'[object Key]'");
shouldBe("importedKey.type", "'secret'");
shouldBe("importedKey.algorithm.name", "'AES-KW'");
shouldBe("importedKey.algorithm.length", "256");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>