jiewen_tan@apple.com | 9ff4601 | 2017-03-16 22:32:20 +0000 | [diff] [blame] | 1 | <!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> |
| 12 | description("Test importing a JWK ECDH public key and export it in SPKI format"); |
| 13 | |
| 14 | jsTestIsAsync = true; |
| 15 | |
| 16 | var jwkKey = { |
| 17 | kty: "EC", |
| 18 | crv: "P-256", |
| 19 | x: "1FSVWieTvikFkG1NOyhkUCaMbdQhxwH6aCu4Ez-sRtA", |
| 20 | y: "9jmNTLqM4cjBhdAnHcNI9YQV3O8LFmo-EdZWk8ntAaI", |
| 21 | }; |
| 22 | var expectedSpkiKey = "3059301306072a8648ce3d020106082a8648ce3d03010703420004d454955a2793be2905906d4d3b286450268c6dd421c701fa682bb8133fac46d0f6398d4cba8ce1c8c185d0271dc348f58415dcef0b166a3e11d65693c9ed01a2"; |
| 23 | var extractable = true; |
| 24 | |
| 25 | debug("Importing a key..."); |
| 26 | crypto.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> |