RSA algorithm is asymmetric cryptography algorithm. Asymmetric actually means that it works on two different keys i.e. Public Key and Private Key. As the name describes that the Public Key is given to everyone and Private key is kept private.
An example of asymmetric cryptography :
- A client (for example browser) sends its public key to the server and requests for some data.
- The server encrypts the data using client’s public key and sends the encrypted data.
- Client receives this data and decrypts it.
- Since this is asymmetric, nobody else except browser can decrypt the data even if a third party has public key of browser
The Public key is used to encrypt the data and Private key is used for decrypting the data
- We have used forge package of node to create RSA keys
- First we import the package node-forge and use PUblic Key Infrastructure(pki) module of forge package to generate RSA keys
- rsa.generateKeyPair creates a new key pair with random modulus. The first parameter specifies the modulus/key size in bits, second the exponent
- Clone the folder
- Inside the project directory open command line
- npm Install
- node rsaKeyPairGenerator.js
The output will be in the form of JSON Object named keys, having public and private keys
CODE BY MOHIT BHAT