Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
A short working example of using the node-rsa module for public key encryption.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
|Failed to load latest commit information.|
When I was trying to make node-rsa work, I felt that the instructions were a little bit cryptic. It took way too much time for figure out the hyphenated argument structure, ie, pkcs1-public. Also, I'm not a huge expert in encryption stuff so it took way too long to figure out that the key produced by ssh-keygen was wrong and what to do about fixing it. I decided that the things I learned need to be documented for posterity. So, when I got it working, I tuned this up for readability and put it in a repo so that you can find it. It does three things. 1) Encrypt with public key/decrypt with private key, both from files 2) Encrypt with private key/decrypt with private key, both from files 3) Generate keys to use for decryption and print them out Change the variable testName to try them out. Just navigate to the directory and run the file: node testNodeRsa.js Bonus! For your convenience, here is the command to convert the .pub generated by ssh-keygen into a .pem: ssh-keygen -f keyName.pub -e -m pem > keyName.pem You're welcome. CHAPTER TWO I want to be able to use the keys in a browser. I figured these learnings were worth documenting, too. I used Browserify. browserify testNodeRsaBrowser.js -o testNodeRsaBrowserBrowserify.js If you put this repository someplace you can serve html, it will let you play with it. You can also play with it at: http://genericwhite.com/rsaEncryptionDemo/testNodeRsaBrowser.html CHAPTER THREE My interest in public key encryption continues. I wanted to be able to actually use a tool to play so I wrote one. It does these things: 1) Generate a key pair. 2) Extract a public key from a private key. 3) Manually enter public or private key. 4) Create a crypto text string from plain text input. 5) Extract plain text from a crypto string. You can play with this at: http://genericwhite.com/rsaEncryptionDemo/ If you have any suggestions, improvements or elaborations, I'm happy to see them. Fork!! Best, TQ White II 1/1/18