blob: 5947bd4b7e28079f58d4d01a5e47056401b46f2b [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 AES-CBC encrypt and decrypt functions with a 256 bit key.");
jsTestIsAsync = true;
var keyData = hexStringToUint8Array("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
var iv = hexStringToUint8Array("000102030405060708090a0b0c0d0e0f");
var plaintext = hexStringToUint8Array("6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710");
var extractable = true;
debug("Importing a raw AES key from string literal...");
crypto.subtle.importKey("raw", keyData, "aes-cbc", extractable, ["encrypt", "decrypt"]).then(function(result) {
key = result;
shouldBe("key.type", "'secret'");
shouldBe("key.extractable", "true");
shouldBe("key.algorithm.name", "'AES-CBC'");
shouldBe("key.algorithm.length", "256");
shouldBe("key.usages", "['decrypt', 'encrypt']");
debug("Using the key to encrypt plaintext...");
return crypto.subtle.encrypt({name: "aes-cbc", iv: iv}, key, plaintext);
}).then(function(result) {
encryptionResult = result;
shouldBe("bytesToHexString(new Uint8Array(encryptionResult))", "'f58c4c04d6e5f1ba779eabfb5f7bfbd69cfc4e967edb808d679f777bc6702c7d39f23369a9d9bacfa530e26304231461b2eb05e2c39be9fcda6c19078c6a9d1b3f461796d6b0d6b2e0c2a72b4d80e644'");
debug("Decrypting it back...");
return crypto.subtle.decrypt({name: "aes-cbc", iv: iv}, key, result);
}).then(function(result) {
decryptionResult = result;
shouldBe("new Uint8Array(decryptionResult)", "plaintext");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>