blob: b808b98fd03a8f6ec9a4109da8fb6d60b8aeea2a [file] [log] [blame]
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -07001<?xml version = "1.0" encoding="utf-8" ?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3"DTD/xhtml1-strict.dtd">
4<html xmlns = "http://www.w3.org/1999/xhtml">
5
6<head>
7 <title>NDN Request Example</title>
8 <script language="JavaScript" type="text/javascript" src="securityLib/jsbn.js"></script>
9 <script language="JavaScript" type="text/javascript" src="securityLib/jsbn2.js"></script>
10 <script language="JavaScript" type="text/javascript" src="securityLib/rsa.js"></script>
11 <script language="JavaScript" type="text/javascript" src="securityLib/rsa2.js"></script>
12
13 <script language="JavaScript" type="text/javascript" src="securityLib/sha1.js"></script>
14 <script language="JavaScript" type="text/javascript" src="securityLib/sha256.js"></script>
15 <script language="JavaScript" type="text/javascript" src="securityLib/sha512.js"></script>
16 <script language="JavaScript" type="text/javascript" src="securityLib/md5.js"></script>
17 <script language="JavaScript" type="text/javascript" src="securityLib/ripemd160.js"></script>
18 <script language="JavaScript" type="text/javascript" src="securityLib/base64.js"></script>
19
20 <script language="JavaScript" type="text/javascript" src="securityLib/rsapem-1.1.min.js"></script>
21 <script language="JavaScript" type="text/javascript" src="securityLib/rsasign-1.2.min.js"></script>
22 <script language="JavaScript" type="text/javascript" src="securityLib/asn1hex-1.1.min.js"></script>
23 <script language="JavaScript" type="text/javascript" src="securityLib/x509-1.1.min.js"></script>
24
25
26 <script type="text/javascript">
27 function sign(){
28
29 var input = document.getElementById('contentname').value;
30
31 var _PEM_PRIVATE_KEY_STRING_ = document.getElementById('privateKey').value;
32
33 var rsa = new RSAKey();
34
35 rsa.readPrivateKeyFromPEMString(_PEM_PRIVATE_KEY_STRING_);
36
37 var hSig = rsa.signString(input, "sha256");
38
39 document.getElementById('result').innerHTML = hSig;
40
41 }
42 function verify(){
43 var input = document.getElementById('contentname').value;
44
45 var signature = document.getElementById('result').innerHTML;
46
47 var _PEM_X509CERT_STRING_ = document.getElementById('certificate').value;
48
49 var x509 = new X509();
50
51 x509.readCertPEM(_PEM_X509CERT_STRING_);
52
53 var result = x509.subjectPublicKeyRSA.verifyString(input, signature);
54
55 if(result)
56 document.getElementById('result').innerHTML = 'SIGNATURE VALID';
57 else
58 document.getElementById('result').innerHTML = 'SIGNATURE INVALID';
59
60
61 }
62
63 </script>
64
65
66</head>
67<body >
68 <form>
69
70 <input id="privateKey" type="hidden" value="-----BEGIN RSA PRIVATE KEY-----
71 MIICWwIBAAKBgQDRhGF7X4A0ZVlEg594WmODVVUIiiPQs04aLmvfg8SborHss5gQ
72 Xu0aIdUT6nb5rTh5hD2yfpF2WIW6M8z0WxRhwicgXwi80H1aLPf6lEPPLvN29EhQ
73 NjBpkFkAJUbS8uuhJEeKw0cE49g80eBBF4BCqSL6PFQbP9/rByxdxEoAIQIDAQAB
74 AoGAA9/q3Zk6ib2GFRpKDLO/O2KMnAfR+b4XJ6zMGeoZ7Lbpi3MW0Nawk9ckVaX0
75 ZVGqxbSIX5Cvp/yjHHpww+QbUFrw/gCjLiiYjM9E8C3uAF5AKJ0r4GBPl4u8K4bp
76 bXeSxSB60/wPQFiQAJVcA5xhZVzqNuF3EjuKdHsw+dk+dPECQQDubX/lVGFgD/xY
77 uchz56Yc7VHX+58BUkNSewSzwJRbcueqknXRWwj97SXqpnYfKqZq78dnEF10SWsr
78 /NMKi+7XAkEA4PVqDv/OZAbWr4syXZNv/Mpl4r5suzYMMUD9U8B2JIRnrhmGZPzL
79 x23N9J4hEJ+Xh8tSKVc80jOkrvGlSv+BxwJAaTOtjA3YTV+gU7Hdza53sCnSw/8F
80 YLrgc6NOJtYhX9xqdevbyn1lkU0zPr8mPYg/F84m6MXixm2iuSz8HZoyzwJARi2p
81 aYZ5/5B2lwroqnKdZBJMGKFpUDn7Mb5hiSgocxnvMkv6NjT66Xsi3iYakJII9q8C
82 Ma1qZvT/cigmdbAh7wJAQNXyoizuGEltiSaBXx4H29EdXNYWDJ9SS5f070BRbAIl
83 dqRh3rcNvpY6BKJqFapda1DjdcncZECMizT/GMrc1w==
84 -----END RSA PRIVATE KEY-----"></input>
85
86
87 <input id="certificate" type="hidden" value="-----BEGIN CERTIFICATE-----
88 MIIBvTCCASYCCQD55fNzc0WF7TANBgkqhkiG9w0BAQUFADAjMQswCQYDVQQGEwJK
89 UDEUMBIGA1UEChMLMDAtVEVTVC1SU0EwHhcNMTAwNTI4MDIwODUxWhcNMjAwNTI1
90 MDIwODUxWjAjMQswCQYDVQQGEwJKUDEUMBIGA1UEChMLMDAtVEVTVC1SU0EwgZ8w
91 DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANGEYXtfgDRlWUSDn3haY4NVVQiKI9Cz
92 Thoua9+DxJuiseyzmBBe7Roh1RPqdvmtOHmEPbJ+kXZYhbozzPRbFGHCJyBfCLzQ
93 fVos9/qUQ88u83b0SFA2MGmQWQAlRtLy66EkR4rDRwTj2DzR4EEXgEKpIvo8VBs/
94 3+sHLF3ESgAhAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAEZ6mXFFq3AzfaqWHmCy1
95 ARjlauYAa8ZmUFnLm0emg9dkVBJ63aEqARhtok6bDQDzSJxiLpCEF6G4b/Nv/M/M
96 LyhP+OoOTmETMegAVQMq71choVJyOFE5BtQa6M/lCHEOya5QUfoRF2HF9EjRF44K
97 3OK+u3ivTSj3zwjtpudY5Xo=
98 -----END CERTIFICATE-----"></input>
99
100 Please Enter a Text to sign:<br /><input id="contentname" type="text" name="CONTENTNAME" value="ª²…s–\nXñ­å ’ŠàÄՋk...\…?8ï����šµhello\n�" /> <br />
101
102 </form>
103 <button onclick="sign()">Sign</button>
104 <button onclick="verify()">Verify</button>
105
106
107
108 <p id="result"></p>
109
110</body>
111</html>