blob: f3bd51c3c16c11fe094af3f1d6350f14befdc3d7 [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 unwrapping a JWK key with AES-GCM using an imported key");
jsTestIsAsync = true;
var extractable = true;
var rawKey = asciiToUint8Array("jnOw99oOZFLIEPMr");
var jwkKey = {
kty: "oct",
alg: "A128CBC",
use: "enc",
key_ops: ["encrypt"],
ext: true,
k: "am5Pdzk5b09aRkxJRVBNcg",
};
var aesGcmParams = {
name: "aes-gcm",
iv: asciiToUint8Array("jnOw99oOZFLIEPMr"),
}
var wrappedKey = hexStringToUint8Array("cafd1c61a96285b95c291b6da304a8be03010b8f96e39fc5076d6c6d8a2a6a669fc76f425ad095b9c18eae86a3f9895998b912807840bcb8bfa9493bed2e27169bd7d61d834e38d0644543195a10c3f9d7e19703244b62e11408663ff142cf2f0c29a6c9df7555f2f77ba0");
crypto.subtle.importKey("raw", rawKey, "aes-gcm", extractable, ["unwrapKey"]).then(function(unwrappingKey) {
return crypto.subtle.unwrapKey("jwk", wrappedKey, unwrappingKey, aesGcmParams, {name: "aes-cbc"}, extractable, ["encrypt"]);
}).then(function(cryptoKey) {
return crypto.subtle.exportKey("jwk", cryptoKey);
}).then(function(result) {
unwrappedKey = result;
shouldBe("unwrappedKey.kty", "jwkKey.kty");
shouldBe("unwrappedKey.alg", "jwkKey.alg");
shouldBe("unwrappedKey.key_ops", "jwkKey.key_ops");
shouldBe("unwrappedKey.ext", "jwkKey.ext");
shouldBe("unwrappedKey.k", "jwkKey.k");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>