aes-cbc-generate-key.html 1.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<!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 an AES key using AES-CBC algorithm.");

jsTestIsAsync = true;

var extractable = true;

shouldThrow('crypto.subtle.generateKey("aes-cbc", extractable, ["encrypt", "decrypt"])');
shouldThrow('crypto.subtle.generateKey({name: "aes-cbc"}, extractable, ["encrypt", "decrypt"])');
shouldThrow('crypto.subtle.generateKey({name: "aes-cbc", length: undefined}, extractable, ["encrypt", "decrypt"])');
shouldThrow('crypto.subtle.generateKey({name: "aes-cbc", length: {}}, extractable, ["encrypt", "decrypt"])');

debug("Generating a key...");
crypto.subtle.generateKey({name: "aes-cbc", length: 128}, extractable, ["encrypt", "decrypt"]).then(function(result) {
    key = result;

    shouldBe("key.type", "'secret'");
    shouldBe("key.extractable", "true");
29
    shouldBe("key.algorithm.name", "'AES-CBC'");
30
    shouldBe("key.algorithm.length", "128");
31
    shouldBe("key.usages", "['decrypt', 'encrypt']");
32 33 34 35 36 37 38 39

    finishJSTest();
});
</script>

<script src="../../resources/js-test-post.js"></script>
</body>
</html>