blob: 100c21ce1514aa4685e09448379f712fda8424eb [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("Test importing an EC public and private key for ECDH.");
jsTestIsAsync = true;
var extractable = true;
var publicKeyJSON = {
"kty": "EC",
"crv": "P-256",
"x": "nLDPaTA9r8dh1ORoe07PA55tNKuWSvgIENjVWKSo1vc",
"y": "LVEjOheIkgqG7gihlix576MX-3h54pfa0hRtuZX6HHg"
};
var privateKeyJSON = {
"kty": "EC",
"crv": "P-384",
"d": "pJLOj6kAhMIn4aMveXTTnp_2en6HBew0GbNftgdYK-vUYeCxUgrHbsLdTptj665x",
"x": "5V_ubEnY1SP1znv5wEJc5P9lBwi33lz7CVkBUjl5p_BCYC2zCFRzU2mBO1w_Xvho",
"y": "KPWcxdxQmJKpiNOKjiUZ3j0MT9D72wmT448YUGwXYGxeJCSSRvHOlJg6U2HFvpg-"
};
debug("Importing a public key...");
crypto.subtle.importKey("jwk", publicKeyJSON, {name: "ECDH", namedCurve: "P-256"}, extractable, []).then(function(result) {
publicKey = result;
shouldBe("publicKey.toString()", "'[object CryptoKey]'");
shouldBe("publicKey.type", "'public'");
shouldBe("publicKey.usages", "[]");
shouldBe("publicKey.algorithm.name", "'ECDH'");
shouldBe("publicKey.algorithm.namedCurve", "'P-256'");
debug("\nImporting a private key...");
return crypto.subtle.importKey("jwk", privateKeyJSON, {name: "ECDH", namedCurve: "P-384"}, extractable, ["deriveBits"]);
}).then(function(result) {
privateKey = result;
shouldBe("privateKey.toString()", "'[object CryptoKey]'");
shouldBe("privateKey.type", "'private'");
shouldBe("privateKey.usages", "['deriveBits']");
shouldBe("privateKey.algorithm.name", "'ECDH'");
shouldBe("privateKey.algorithm.namedCurve", "'P-384'");
}).then(finishJSTest, failAndFinishJSTest);
</script>
</body>
</html>