OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="../resources/js-test.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 an EC key for ECDSA."); |
| 13 |
| 14 jsTestIsAsync = true; |
| 15 |
| 16 var extractable = true; |
| 17 |
| 18 var publicKeyJSON = { |
| 19 "kty": "EC", |
| 20 "crv": "P-256", |
| 21 "x": "fBEMZtz9qAf25p5F3bPHT2mhSE0gPo3Frajpqd18s8c", |
| 22 "y": "DfRImG5RveXRV2-ZkB-cLGqAakf9kHZDpyuDVZfvyMY" |
| 23 }; |
| 24 |
| 25 var privateKeyJSON = { |
| 26 "kty": "EC", |
| 27 "crv": "P-256", |
| 28 "d": "H-M5UMX0YRJK6ZLCvf3xxzsWFfVxvVZ-YNGaofSM30I", |
| 29 "x": "fBEMZtz9qAf25p5F3bPHT2mhSE0gPo3Frajpqd18s8c", |
| 30 "y": "DfRImG5RveXRV2-ZkB-cLGqAakf9kHZDpyuDVZfvyMY" |
| 31 }; |
| 32 |
| 33 var data = asciiToUint8Array("Hello, world!"); |
| 34 |
| 35 debug("Importing a public key..."); |
| 36 crypto.subtle.importKey("jwk", publicKeyJSON, { name: "ECDSA", namedCurve: "P-25
6" }, extractable, ["verify"]).then(function(result) { |
| 37 publicKey = result; |
| 38 debug("\nImporting a private key..."); |
| 39 return crypto.subtle.importKey("jwk", privateKeyJSON, { name: "ECDSA", named
Curve: "P-256" }, extractable, ["sign"]); |
| 40 }).then(function(result) { |
| 41 privateKey = result; |
| 42 debug("\nSigning some text..."); |
| 43 return crypto.subtle.sign({ name: "ECDSA", hash: { name: "SHA-1" } }, privat
eKey, data); |
| 44 }).then(function(result) { |
| 45 signature = result; |
| 46 |
| 47 debug("\nVerifying the signature..."); |
| 48 return crypto.subtle.verify({ name: "ECDSA", hash: { name: "SHA-1" } }, publ
icKey, signature, data); |
| 49 }).then(function(result) { |
| 50 verificationResult = result; |
| 51 shouldBe("verificationResult", "true"); |
| 52 debug("\nVerifying a bad signature..."); |
| 53 return crypto.subtle.verify({ name: "ECDSA", hash: { name: "SHA-1" } }, publ
icKey, new Uint8Array(256), data); |
| 54 }).then(function(result) { |
| 55 verificationResult = result; |
| 56 shouldBe("verificationResult", "false"); |
| 57 }).then(finishJSTest, failAndFinishJSTest); |
| 58 </script> |
| 59 |
| 60 </body> |
| 61 </html> |
OLD | NEW |