I need to know how to generate 'rsa' key-pair on the client-side using angular2. I need to generate private/public key pair and save the private key into database and want to use public key inside the client side. How can I implement this?
I found this https://www.npmjs.com/package/generate-rsa-keypair for generating key pair. But its for node? Can I implement it into my client side? If yes how? Is any other way to implement this?
you must use https://github.com/juliangruber/keypair library
then import it in angular component like
import * as keypair from 'keypair';
and use library method
const pubprivkey = keypair();
console.log(pubprivkey);
it will return object of RSA public and private key
{ public: '-----BEGIN RSA PUBLIC KEY-----\r\nMIGJAoGBAM3CosR73CBNcJsLvAgMBAAE=\r\n-----END RSA PUBLIC KEY-----\n',
private: '-----BEGIN RSA PRIVATE KEY-----\r\nMIICXAIBAAKBgQDNwqLEe9wgTXNHoyxi7Ia\r\nPQUCQCwWU4U+v4lD7uYBw00Ga/xt+7+UqFPlPVdz1yyr4q24Zxaw0LgmuEvgU5dycq8N7Jxj\r\nTubX0MIRR+G9fmDBBl8=\r\n-----END RSA PRIVATE KEY-----\n' }
来源:https://stackoverflow.com/questions/44673186/how-to-generate-rsa-key-pair-in-client-side-using-angular2