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 RSA key for RSASSA-PKCS1-v1_5."); | |
13 | |
14 jsTestIsAsync = true; | |
15 | |
16 var extractable = true; | |
17 | |
18 var publicKeyJSON = { | |
19 kty: "RSA", | |
20 alg: "RS256", | |
21 n: Base64URL.stringify(hexStringToUint8Array("ADC0940AFECE7351D56A6D432210B3
AA49D38566B03A9F102E4F198B2DA9D740728D01426A3A058B2B805A5F91D565D969FE318AD2D1AD
A713F5A829CC8CDCF8C6CB4872068164063B6D651A2226CB97ED67E0FC6C702A473DB2D79A730F87
38084A2EED74922C3A119D1D101B932C0E10FAB36815F66C0792BB640B1B4C59D062FBBEDAB3CC06
9A535195D70E4A06432CAF149C24A00353A0B99F7CF5B17273CB4E38421BD315127CF4B3DCB3D20A
7C98CFAF1A0E398A55E347FA283CE7B39273259B1B2132DC18B0EB8AAE9F78EE525356B09DF39E09
0E76D7985B2B71E50AF85CA36CE91F8CCB2ABBD8A529D369890D98A2CA2825C4C2FF8B7FBF09E79C
0B")), | |
22 e: Base64URL.stringify(hexStringToUint8Array("010001")), | |
23 }; | |
24 | |
25 var privateKeyJSON = { | |
26 kty: "RSA", | |
27 alg: "RS256", | |
28 n: Base64URL.stringify(hexStringToUint8Array("ADC0940AFECE7351D56A6D432210B3
AA49D38566B03A9F102E4F198B2DA9D740728D01426A3A058B2B805A5F91D565D969FE318AD2D1AD
A713F5A829CC8CDCF8C6CB4872068164063B6D651A2226CB97ED67E0FC6C702A473DB2D79A730F87
38084A2EED74922C3A119D1D101B932C0E10FAB36815F66C0792BB640B1B4C59D062FBBEDAB3CC06
9A535195D70E4A06432CAF149C24A00353A0B99F7CF5B17273CB4E38421BD315127CF4B3DCB3D20A
7C98CFAF1A0E398A55E347FA283CE7B39273259B1B2132DC18B0EB8AAE9F78EE525356B09DF39E09
0E76D7985B2B71E50AF85CA36CE91F8CCB2ABBD8A529D369890D98A2CA2825C4C2FF8B7FBF09E79C
0B")), | |
29 e: Base64URL.stringify(hexStringToUint8Array("010001")), | |
30 d: Base64URL.stringify(hexStringToUint8Array("78D2D2DFB682CFB45748D3C3FC3B4B
049EA3E53F1C4B17734410A33DA23A59C1AA269D7A96ADD44F0BA80CB02A940F681989B6DFC76C21
6A6EB9C3FF950B5B59EFBB4A9C6823AFEF99819FED85541EFD7E0C5F6A88E992ACC99DC4C9D53B36
1763C45A4FAB613E39FF27971F2D5DB123F2F0B2B32D9A9752C8D9605F4CD3521C2DB9A86000A304
0A16231F61278C7747C3AB18DBEC00A5D71023B50B134A28E51CDB419A66BA170DF618817342F786
1174AA8E7499B974DBFEB9FC643B0E95645C1C4D81104BCE53DA6E6CF31B6A0085F79F2E0626482D
68A5A0A45C4EAF45640D58D2F8E5164D64560CDEEA0982138CA867A870CD01A63742847ACF3A516F
49")), | |
31 p: Base64URL.stringify(hexStringToUint8Array("E26893B808CA31E1F9B89E4A077F7B
414C216E46048126DC0369A27E64A4BC4DB4D7C81BE79AA40472B5795AF27F5FE6E372CD95CE8EFD
A93A81FCDD64866F4B93421A33E5D2AD3DA65529BBCA85392B2907003AEEA187EFA9459592E7FDDE
328254BBC1F2EBBB8FF962CF2A2CBB3E0EA54BBE2C29A2C3A7CB25AAC0CE405E9D")), | |
32 q: Base64URL.stringify(hexStringToUint8Array("C4762BCE48AFB669F3FEC19C867586
734ABEA433A42A2729B51A6FDA93052085F19C55F968C7845C866356E8D7B70532D5494520DD8664
94AFCB9289EFD9AEFD7C8D9C51CCCDE747F80DDE7B7BBC875514AD917EBD4BB5FDEE14FF1EBB34DD
5D79DCD448ACA737BA459773A4B9284C056195F9CC3338F75C5407D5B9997150C7")), | |
33 dp: Base64URL.stringify(hexStringToUint8Array("7C1CC3CD80D40660501A8A7B1E7D1
DBDFFD3DBB57A46AA5CB56A34EF809065C15B3F66AD155B4A4A3DEF8964F7C62776547CDC8220C77
5FA4CDE71159443B5C302289C6092BDD8C610E66288554E8EB640395C40F20B8E8F2C85BEA6D791E
D3A5703C8215BDF29E494DB3BA16CFFFFD6DB7A17F7F1A30E0A6F6C689C64F41869")), | |
34 dq: Base64URL.stringify(hexStringToUint8Array("8E61360E220F761C0380B5C042921
A06A43CD5B3B75DF553FCB4542C0C30C3094FB90575E3C1F4E33961F5327A6361991D8A245755347
8E0692717E46FB74B62DA49A6E8818D17F8C88504A06964908FD09499C5485AFE62319175F347A96
064C6548C64BEFBD11F662004E7746907EF3E71FABF4AC016450B81421B6860FF31")), | |
35 qi: Base64URL.stringify(hexStringToUint8Array("6025FFA4BC1B3010354E1547D1673
09A7CADA8D72B3021304E6EC1C80D9E53A9D66D0AD42EF7FB9BDFE4CDF2D4723B27A405650501B92
4C5CCCB44AAE29B706F2C2C6B9F86F0A00E38E4762F7BF8842F84CACF5FB6014CFF78B4A38D1E790
1F86F785A3DB9EDAC878C83C23394EB9560A7FDFB642E283A1679175DECDB1DC539")) | |
36 }; | |
37 | |
38 var data = asciiToUint8Array("Hello, world!"); | |
39 | |
40 debug("Importing a public key..."); | |
41 crypto.subtle.importKey("jwk", publicKeyJSON, { name: "RSASSA-PKCS1-v1_5", hash:
{name: "SHA-256"} }, extractable, ["verify"]).then(function(result) { | |
42 publicKey = result; | |
43 debug("\nImporting a private key..."); | |
44 return crypto.subtle.importKey("jwk", privateKeyJSON, { name: "RSASSA-PKCS1-
v1_5", hash: {name: "SHA-256"} }, extractable, ["sign"]); | |
45 }).then(function(result) { | |
46 privateKey = result; | |
47 debug("\nSigning some text..."); | |
48 return crypto.subtle.sign({ name: "RSASSA-PKCS1-v1_5"}, privateKey, data); | |
49 }).then(function(result) { | |
50 signature = result; | |
51 shouldBe("bytesToHexString(new Uint8Array(signature))", "'0fd9a8aef4cc1876c0
b762545336c6d1fb315ae16ae4b5e4bf34d384d8585ea7a01e76ea09ee7f7ee8d1c122e7dd15b7c9
4a573b2aa07203e8d13bc6fd16156cd8e5f0c15a15dccb62d152127fca09882fb53bc3e60ab586d1
5b95cf411e3aab4a1c231a7e91aab09ee3d4b13d11e97505ddff77683470da510ee76e8bd530c56a
85f901626a5a710f716f113dfe9cf6c473ee16fa248aea3480a1033abe30f4c1243289a661e64d78
18b55698280688097135968c6d4b029496d85cab2a67e4696737781f70e4392c7df71bbd6c924659
47f029a1de48160aced11b5721b1cd25039fe2c16c2b38de73df3b9a83e3ea755fd0cfe51ca06b61
fadf6d84677f95'"); | |
52 | |
53 debug("\nVerifying the signature..."); | |
54 return crypto.subtle.verify({ name: "RSASSA-PKCS1-v1_5" }, publicKey, signat
ure, data); | |
55 }).then(function(result) { | |
56 verificationResult = result; | |
57 shouldBe("verificationResult", "true"); | |
58 debug("\nVerifying a bad signature..."); | |
59 return crypto.subtle.verify({ name: "RSASSA-PKCS1-v1_5" }, publicKey, new Ui
nt8Array(256), data); | |
60 }).then(function(result) { | |
61 verificationResult = result; | |
62 shouldBe("verificationResult", "false"); | |
63 }).then(finishJSTest, failAndFinishJSTest); | |
64 </script> | |
65 | |
66 </body> | |
67 </html> | |
OLD | NEW |