blob: 6b094a2024279b8a91e40350d8b8e91316e2d406 [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 raw ECDH key and then export it in jwk format");
jsTestIsAsync = true;
var expectedJwkKey = {
kty: "EC",
use: "enc",
ext: true,
crv: "P-256",
x: "1FSVWieTvikFkG1NOyhkUCaMbdQhxwH6aCu4Ez-sRtA",
y: "9jmNTLqM4cjBhdAnHcNI9YQV3O8LFmo-EdZWk8ntAaI",
};
var rawKey = hexStringToUint8Array("04d454955a2793be2905906d4d3b286450268c6dd421c701fa682bb8133fac46d0f6398d4cba8ce1c8c185d0271dc348f58415dcef0b166a3e11d65693c9ed01a2");
var extractable = true;
debug("Importing a key...");
crypto.subtle.importKey("raw", rawKey, { name: "ECDH", namedCurve: "P-256" }, extractable, [ ]).then(function(result) {
return crypto.subtle.exportKey("jwk", result);
}).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>