|
| 1 | +# Node-RSA |
| 2 | + |
| 3 | +Pure JavaScript Node.js RSA library |
| 4 | +No needed OpenSSL |
| 5 | + |
| 6 | +Based on jsbn library from Tom Wu http://www-cs-students.stanford.edu/~tjw/jsbn/ and node.js adaptation https://github.com/eschnou/node-bignumber |
| 7 | + |
| 8 | +## Building and Installing |
| 9 | + |
| 10 | +```shell |
| 11 | +npm install node-rsa |
| 12 | +``` |
| 13 | + |
| 14 | +#### Testing |
| 15 | + |
| 16 | +```shell |
| 17 | +npm test |
| 18 | +``` |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +### Create instance |
| 23 | +#### "Empty" key |
| 24 | +```js |
| 25 | +var key = new NodeRSA(); |
| 26 | +``` |
| 27 | + |
| 28 | +### Generate new key 512bit-length and with public exponent 65537 |
| 29 | +```js |
| 30 | +var key = NodeRSA({b: 512}); |
| 31 | +``` |
| 32 | + |
| 33 | +### Load key from PEM string |
| 34 | + |
| 35 | +```js |
| 36 | +var key = new NodeRSA('-----BEGIN RSA PRIVATE KEY-----\n'+ |
| 37 | + 'MIIBOQIBAAJAVY6quuzCwyOWzymJ7C4zXjeV/232wt2ZgJZ1kHzjI73wnhQ3WQcL\n'+ |
| 38 | + 'DFCSoi2lPUW8/zspk0qWvPdtp6Jg5Lu7hwIDAQABAkBEws9mQahZ6r1mq2zEm3D/\n'+ |
| 39 | + 'VM9BpV//xtd6p/G+eRCYBT2qshGx42ucdgZCYJptFoW+HEx/jtzWe74yK6jGIkWJ\n'+ |
| 40 | + 'AiEAoNAMsPqwWwTyjDZCo9iKvfIQvd3MWnmtFmjiHoPtjx0CIQCIMypAEEkZuQUi\n'+ |
| 41 | + 'pMoreJrOlLJWdc0bfhzNAJjxsTv/8wIgQG0ZqI3GubBxu9rBOAM5EoA4VNjXVigJ\n'+ |
| 42 | + 'QEEk1jTkp8ECIQCHhsoq90mWM/p9L5cQzLDWkTYoPI49Ji+Iemi2T5MRqwIgQl07\n'+ |
| 43 | + 'Es+KCn25OKXR/FJ5fu6A6A+MptABL3r8SEjlpLc=\n'+ |
| 44 | + '-----END RSA PRIVATE KEY-----'); |
| 45 | +``` |
| 46 | + |
| 47 | +Also you can use next methods: |
| 48 | + |
| 49 | +```js |
| 50 | +key.generateKeyPair(bits, exp); // exp = 65537 by default |
| 51 | +key.loadFromPEM(); |
| 52 | +``` |
| 53 | + |
| 54 | +### Export keys |
| 55 | +```js |
| 56 | +key.toPrivatePEM(); |
| 57 | +key.toPublicPEM(); |
| 58 | +``` |
| 59 | + |
| 60 | +### Test key |
| 61 | +```js |
| 62 | +key.isPrivate(); |
| 63 | +key.isPublic(); |
| 64 | +``` |
| 65 | + |
| 66 | + |
| 67 | +## Contributing |
| 68 | + |
| 69 | +Questions, comments, bug reports, and pull requests are all welcome. |
| 70 | + |
| 71 | +## License For NodeRSA.js |
| 72 | + |
| 73 | +BSD |
| 74 | + |
| 75 | +## Licensing For Code used in rsa.js and jsbn.js |
| 76 | + |
| 77 | +Copyright (c) 2003-2005 Tom Wu |
| 78 | +All Rights Reserved. |
| 79 | + |
| 80 | +Permission is hereby granted, free of charge, to any person obtaining |
| 81 | +a copy of this software and associated documentation files (the |
| 82 | +"Software"), to deal in the Software without restriction, including |
| 83 | +without limitation the rights to use, copy, modify, merge, publish, |
| 84 | +distribute, sublicense, and/or sell copies of the Software, and to |
| 85 | +permit persons to whom the Software is furnished to do so, subject to |
| 86 | +the following conditions: |
| 87 | + |
| 88 | +The above copyright notice and this permission notice shall be |
| 89 | +included in all copies or substantial portions of the Software. |
| 90 | +THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, |
| 91 | +EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY |
| 92 | +WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. |
| 93 | + |
| 94 | +IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL, |
| 95 | +INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER |
| 96 | +RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF |
| 97 | +THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT |
| 98 | +OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 99 | + |
| 100 | +In addition, the following condition applies: |
| 101 | + |
| 102 | +All redistributions must retain an intact copy of this copyright notice |
| 103 | +and disclaimer. |
0 commit comments