blob: c35ca2e1ca5640b6d329d76abb17f7dd61829136 [file] [log] [blame]
jiewen_tan@apple.com9ff46012017-03-16 22:32:20 +00001<!DOCTYPE html>
2<html>
3<head>
4<script src="../../resources/js-test-pre.js"></script>
5<script src="../resources/common.js"></script>
6</head>
7<body>
8<p id="description"></p>
9<div id="console"></div>
10
11<script>
12description("Test importing a JWK ECDH public key and export it in SPKI format");
13
14jsTestIsAsync = true;
15
16var jwkKey = {
17 kty: "EC",
18 crv: "P-256",
19 x: "1FSVWieTvikFkG1NOyhkUCaMbdQhxwH6aCu4Ez-sRtA",
20 y: "9jmNTLqM4cjBhdAnHcNI9YQV3O8LFmo-EdZWk8ntAaI",
21};
22var expectedSpkiKey = "3059301306072a8648ce3d020106082a8648ce3d03010703420004d454955a2793be2905906d4d3b286450268c6dd421c701fa682bb8133fac46d0f6398d4cba8ce1c8c185d0271dc348f58415dcef0b166a3e11d65693c9ed01a2";
23var extractable = true;
24
25debug("Importing a key...");
26crypto.subtle.importKey("jwk", jwkKey, { name: "ECDH", namedCurve: "P-256" }, extractable, [ ]).then(function(key) {
27 return crypto.subtle.exportKey("spki", key);
28}).then(function(result) {
29 publicKey = result;
30
31 shouldBe("bytesToHexString(publicKey)", "expectedSpkiKey");
32
33 finishJSTest();
34});
35
36</script>
37
38<script src="../../resources/js-test-post.js"></script>
39</body>
40</html>