Wentao Shang | bd63e46 | 2012-12-03 16:19:33 -0800 | [diff] [blame] | 1 | /** |
Jeff Thompson | 146d7de | 2012-11-17 16:15:28 -0800 | [diff] [blame] | 2 | * @author: Meki Cheraoui |
Jeff Thompson | 745026e | 2012-10-13 12:49:20 -0700 | [diff] [blame] | 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 5 | |
| 6 | var KeyManager = function KeyManager(){ |
| 7 | |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 8 | |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 9 | //Certificate |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 10 | |
| 11 | this.certificate = 'MIIBmzCCAQQCCQC32FyQa61S7jANBgkqhkiG9w0BAQUFADASMRAwDgYDVQQDEwd'+ |
| 12 | |
| 13 | 'heGVsY2R2MB4XDTEyMDQyODIzNDQzN1oXDTEyMDUyODIzNDQzN1owEjEQMA4GA1'+ |
| 14 | |
| 15 | 'UEAxMHYXhlbGNkdjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA4X0wp9goq'+ |
| 16 | |
| 17 | 'xuECxdULcr2IHr9Ih4Iaypg0Wy39URIup8/CLzQmdsh3RYqd55hqonu5VTTpH3i'+ |
| 18 | |
| 19 | 'MLx6xZDVJAZ8OJi7pvXcQ2C4Re2kjL2c8SanI0RfDhlS1zJadfr1VhRPmpivcYa'+ |
| 20 | |
| 21 | 'wJ4aFuOLAi+qHFxtN7lhcGCgpW1OV60oXd58CAwEAATANBgkqhkiG9w0BAQUFAA'+ |
| 22 | |
| 23 | 'OBgQDLOrA1fXzSrpftUB5Ro6DigX1Bjkf7F5Bkd69hSVp+jYeJFBBlsILQAfSxU'+ |
| 24 | |
| 25 | 'ZPQtD+2Yc3iCmSYNyxqu9PcufDRJlnvB7PG29+L3y9lR37tetzUV9eTscJ7rdp8'+ |
| 26 | |
| 27 | 'Wt6AzpW32IJ/54yKNfP7S6ZIoIG+LP6EIxq6s8K1MXRt8uBJKw=='; |
| 28 | |
| 29 | |
| 30 | //this.publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDhfTCn2CirG4QLF1QtyvYgev0iHghrKmDRbLf1REi6nz8IvNCZ2yHdFip3nmGqie7lVNOkfeIwvHrFkNUkBnw4mLum9dxDYLhF7aSMvZzxJqcjRF8OGVLXMlp1+vVWFE+amK9xhrAnhoW44sCL6ocXG03uWFwYKClbU5XrShd3nwIDAQAB'; |
| 31 | this.publicKey ='30819F300D06092A864886F70D010101050003818D0030818902818100E17D30A7D828AB1B840B17542DCAF6207AFD221E086B2A60D16CB7F54448BA9F3F08BCD099DB21DD162A779E61AA89EEE554D3A47DE230BC7AC590D524067C3898BBA6F5DC4360B845EDA48CBD9CF126A723445F0E1952D7325A75FAF556144F9A98AF7186B0278685B8E2C08BEA87171B4DEE585C1828295B5395EB4A17779F0203010001'; |
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 32 | //Private Key |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 33 | |
| 34 | this.privateKey ='MIICXQIBAAKBgQDhfTCn2CirG4QLF1QtyvYgev0iHghrKmDRbLf1REi6nz8IvNCZ2yHdFip3nmGqie7lVNOkfeIwvHrFkNUkBnw4mLum9dxDYLhF7aSMvZzxJqcjRF8OGVLXMlp1+vVWFE+amK9xhrAnhoW44sCL6ocXG03uWFwYKClbU5XrShd3nwIDAQABAoGAGkv6T6jC3WmhFZYL6CdCWvlc6gysmKrhjarrLTxgavtFY6R5g2ft5BXAsCCVbUkWxkIFSKqxpVNl0gKZCNGEzPDN6mHJOQI/h0rlxNIHAuGfoAbCzALnqmyZivhJAPGijAyKuU9tczsst5+Kpn+bn7ehzHQuj7iwJonS5WbojqECQQ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7wJAQNXyoizuGEltiSaBXx4H29EdXNYWDJ9SS5f070BRbAIl'+ |
| 63 | 'dqRh3rcNvpY6BKJqFapda1DjdcncZECMizT/GMrc1w=='; |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 64 | |
| 65 | */ |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | |
| 69 | KeyManager.prototype.verify = function verify(message,signature){ |
| 70 | |
| 71 | var input = message; |
| 72 | |
| 73 | var _PEM_X509CERT_STRING_ = this.certificate; |
| 74 | |
| 75 | var x509 = new X509(); |
| 76 | |
| 77 | x509.readCertPEM(_PEM_X509CERT_STRING_); |
| 78 | |
| 79 | var result = x509.subjectPublicKeyRSA.verifyString(input, signature); |
| 80 | |
| 81 | return result; |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | KeyManager.prototype.sign= function sign(message){ |
| 85 | |
| 86 | var input = message; |
| 87 | |
| 88 | var _PEM_PRIVATE_KEY_STRING_ = this.privateKey; |
| 89 | |
| 90 | var rsa = new RSAKey(); |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 91 | |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 92 | rsa.readPrivateKeyFromPEMString(_PEM_PRIVATE_KEY_STRING_); |
| 93 | |
| 94 | var hSig = rsa.signString(input, "sha256"); |
| 95 | |
| 96 | return hSig; |
| 97 | |
| 98 | }; |
| 99 | |
| 100 | |
| 101 | |
| 102 | var globalKeyManager = new KeyManager(); |
| 103 | //var KeyPair = { "public" : "PUBLIC KEY" , "private" : "PRIVATE KEY" }; |
| 104 | |
| 105 | |