javascript - How to generate rsa key pair in client side using angular2? - Stack Overflow

I need to know how to generate 'rsa' key-pair on the client-side using angular2. I need to g

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
Add a ment  | 

1 Answer 1

Reset to default 6

you 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信