blob: 03588d164cbc852dafbe7eb38e651f8abc349caa [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 importing a SPKI ECDH key and exporting it in JWK format");
jsTestIsAsync = true;
var spkiKey = hexStringToUint8Array("3059301306072a8648ce3d020106082a8648ce3d03010703420004c3ee3a2c3380072b9b2a59fed2cada65121806e22c4f4f8a25e740fc3e54d75d86c200298e6dfc1611d185eedbdb3c2661b0eb0441f7fd57c90d08112e9ae71c");
var expectedJwkKey = {
kty: "EC",
use: "enc",
ext: true,
crv: "P-256",
x: "w-46LDOAByubKln-0sraZRIYBuIsT0-KJedA_D5U110",
y: "hsIAKY5t_BYR0YXu29s8JmGw6wRB9_1XyQ0IES6a5xw",
};
var extractable = true;
debug("Importing a key...");
crypto.subtle.importKey("spki", spkiKey, {name: "ECDH", namedCurve: "P-256"}, extractable, [ ]).then(function(key) {
return crypto.subtle.exportKey("jwk", key);
}).then(function(result) {
publicKey = result;
shouldBe("publicKey.kty", "expectedJwkKey.kty");
shouldBe("publicKey.crv", "expectedJwkKey.crv");
shouldBe("publicKey.x", "expectedJwkKey.x");
shouldBe("publicKey.y", "expectedJwkKey.y");
shouldBe("publicKey.key_ops", "[ ]");
shouldBe("publicKey.ext", "expectedJwkKey.ext");
finishJSTest();
});
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>