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 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?
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./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?
Share Improve this question edited Jun 21, 2017 at 10:17 muetzerich 5,7208 gold badges39 silver badges52 bronze badges asked Jun 21, 2017 at 10:12 KhushiKhushi 1,8696 gold badges28 silver badges48 bronze badges 3- What do you mean with and save the private key into database ?. Do you want to store the key into the IndexedDB in browser? – pedrofb Commented Jun 21, 2017 at 11:48
- i need to store it in my Database MongoDb – Khushi Commented Jun 23, 2017 at 4:05
- For security reasons it is not remended to send a private key along the network. If you need it in the server, generate the keypair in the server and send the public key to browser – pedrofb Commented Jun 23, 2017 at 6:03
1 Answer
Reset to default 6you must use https://github./juliangruber/keypair library
then import it in angular ponent 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' }
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744886650a4599159.html
评论列表(0条)