Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 1 | <?xml version = "1.0" encoding="utf-8" ?> |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| 3 | "DTD/xhtml1-strict.dtd"> |
Jeff Burke | 92dd8e4 | 2012-12-08 11:40:31 -0800 | [diff] [blame] | 4 | <!-- |
| 5 | See COPYING for copyright and distribution information. |
| 6 | --> |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 7 | <html xmlns = "http://www.w3.org/1999/xhtml"> |
| 8 | |
| 9 | <head> |
jeff | 7264ee1 | 2012-09-16 17:04:10 -0700 | [diff] [blame] | 10 | <title>NDN Image Parsing</title> |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 11 | |
Alexander Afanasyev | 2a2c9d2 | 2013-03-13 16:21:32 -0700 | [diff] [blame] | 12 | <script type="text/javascript" src="../build/ndn-js.js"></script> |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 13 | |
| 14 | <script type="text/javascript"> |
| 15 | function sign(){ |
| 16 | |
| 17 | var input = document.getElementById('contentname').value; |
| 18 | |
| 19 | var _PEM_PRIVATE_KEY_STRING_ = document.getElementById('privateKey').value; |
| 20 | |
| 21 | var rsa = new RSAKey(); |
| 22 | |
| 23 | rsa.readPrivateKeyFromPEMString(_PEM_PRIVATE_KEY_STRING_); |
| 24 | |
| 25 | var hSig = rsa.signString(input, "sha256"); |
| 26 | |
| 27 | document.getElementById('result').innerHTML = hSig; |
| 28 | |
| 29 | } |
| 30 | function verify(){ |
| 31 | var input = document.getElementById('contentname').value; |
| 32 | |
| 33 | var signature = document.getElementById('result').innerHTML; |
| 34 | |
| 35 | var _PEM_X509CERT_STRING_ = document.getElementById('certificate').value; |
| 36 | |
| 37 | var x509 = new X509(); |
| 38 | |
| 39 | x509.readCertPEM(_PEM_X509CERT_STRING_); |
| 40 | |
| 41 | var result = x509.subjectPublicKeyRSA.verifyString(input, signature); |
| 42 | |
| 43 | if(result) |
| 44 | document.getElementById('result').innerHTML = 'SIGNATURE VALID'; |
| 45 | else |
| 46 | document.getElementById('result').innerHTML = 'SIGNATURE INVALID'; |
| 47 | |
| 48 | |
| 49 | } |
| 50 | |
| 51 | </script> |
| 52 | |
| 53 | |
| 54 | </head> |
| 55 | <body > |
| 56 | <form> |
| 57 | |
| 58 | <input id="privateKey" type="hidden" value="-----BEGIN RSA PRIVATE KEY----- |
| 59 | MIICWwIBAAKBgQDRhGF7X4A0ZVlEg594WmODVVUIiiPQs04aLmvfg8SborHss5gQ |
| 60 | Xu0aIdUT6nb5rTh5hD2yfpF2WIW6M8z0WxRhwicgXwi80H1aLPf6lEPPLvN29EhQ |
| 61 | NjBpkFkAJUbS8uuhJEeKw0cE49g80eBBF4BCqSL6PFQbP9/rByxdxEoAIQIDAQAB |
| 62 | AoGAA9/q3Zk6ib2GFRpKDLO/O2KMnAfR+b4XJ6zMGeoZ7Lbpi3MW0Nawk9ckVaX0 |
| 63 | ZVGqxbSIX5Cvp/yjHHpww+QbUFrw/gCjLiiYjM9E8C3uAF5AKJ0r4GBPl4u8K4bp |
| 64 | bXeSxSB60/wPQFiQAJVcA5xhZVzqNuF3EjuKdHsw+dk+dPECQQDubX/lVGFgD/xY |
| 65 | uchz56Yc7VHX+58BUkNSewSzwJRbcueqknXRWwj97SXqpnYfKqZq78dnEF10SWsr |
| 66 | /NMKi+7XAkEA4PVqDv/OZAbWr4syXZNv/Mpl4r5suzYMMUD9U8B2JIRnrhmGZPzL |
| 67 | x23N9J4hEJ+Xh8tSKVc80jOkrvGlSv+BxwJAaTOtjA3YTV+gU7Hdza53sCnSw/8F |
| 68 | YLrgc6NOJtYhX9xqdevbyn1lkU0zPr8mPYg/F84m6MXixm2iuSz8HZoyzwJARi2p |
| 69 | aYZ5/5B2lwroqnKdZBJMGKFpUDn7Mb5hiSgocxnvMkv6NjT66Xsi3iYakJII9q8C |
| 70 | Ma1qZvT/cigmdbAh7wJAQNXyoizuGEltiSaBXx4H29EdXNYWDJ9SS5f070BRbAIl |
| 71 | dqRh3rcNvpY6BKJqFapda1DjdcncZECMizT/GMrc1w== |
| 72 | -----END RSA PRIVATE KEY-----"></input> |
| 73 | |
| 74 | |
| 75 | <input id="certificate" type="hidden" value="-----BEGIN CERTIFICATE----- |
| 76 | MIIBvTCCASYCCQD55fNzc0WF7TANBgkqhkiG9w0BAQUFADAjMQswCQYDVQQGEwJK |
| 77 | UDEUMBIGA1UEChMLMDAtVEVTVC1SU0EwHhcNMTAwNTI4MDIwODUxWhcNMjAwNTI1 |
| 78 | MDIwODUxWjAjMQswCQYDVQQGEwJKUDEUMBIGA1UEChMLMDAtVEVTVC1SU0EwgZ8w |
| 79 | DQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANGEYXtfgDRlWUSDn3haY4NVVQiKI9Cz |
| 80 | Thoua9+DxJuiseyzmBBe7Roh1RPqdvmtOHmEPbJ+kXZYhbozzPRbFGHCJyBfCLzQ |
| 81 | fVos9/qUQ88u83b0SFA2MGmQWQAlRtLy66EkR4rDRwTj2DzR4EEXgEKpIvo8VBs/ |
| 82 | 3+sHLF3ESgAhAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAEZ6mXFFq3AzfaqWHmCy1 |
| 83 | ARjlauYAa8ZmUFnLm0emg9dkVBJ63aEqARhtok6bDQDzSJxiLpCEF6G4b/Nv/M/M |
| 84 | LyhP+OoOTmETMegAVQMq71choVJyOFE5BtQa6M/lCHEOya5QUfoRF2HF9EjRF44K |
| 85 | 3OK+u3ivTSj3zwjtpudY5Xo= |
| 86 | -----END CERTIFICATE-----"></input> |
| 87 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 88 | Please Enter a Text to sign:<br /><input id="contentname" type="text" name="CONTENTNAME" value="/ndn/abc" /> <br /> |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 89 | |
| 90 | </form> |
| 91 | <button onclick="sign()">Encode</button> |
| 92 | <button onclick="verify()">Parse</button> |
| 93 | |
| 94 | <script type="text/javascript"> |
| 95 | |
jeff | 7264ee1 | 2012-09-16 17:04:10 -0700 | [diff] [blame] | 96 | var srcString = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg=='; |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 97 | var link = document.createElement('img'); |
jeff | 7264ee1 | 2012-09-16 17:04:10 -0700 | [diff] [blame] | 98 | link.setAttribute('src', srcString); |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 99 | |
| 100 | document.body.appendChild(link); |
| 101 | |
| 102 | </script> |
| 103 | |
| 104 | <img src="data:image/png;base64, |
| 105 | iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP |
| 106 | C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA |
| 107 | AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J |
| 108 | REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq |
| 109 | ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0 |
| 110 | vr4MkhoXe0rZigAAAABJRU5ErkJggg==" alt="Red dot" /> |
| 111 | |
| 112 | <p id="result"></p> |
| 113 | |
| 114 | </body> |
| 115 | </html> |