How to generate rsa key pair in client side using angular2?

狂风中的少年 提交于 2019-12-08 04:55:16

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!