如何使用angular2在客户端生成rsa密钥对? [英] How to generate rsa key pair in client side using angular2?

查看:235
本文介绍了如何使用angular2在客户端生成rsa密钥对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何使用angular2在客户端生成"rsa"密钥对. 我需要生成私钥/公钥对,并将私钥保存到数据库中,并想在客户端内部使用公钥.我该如何实施?

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?

我发现了这个 https://www.npmjs.com/package/generate- rsa-keypair 用于生成密钥对.但是它的节点?我可以在客户端实现它吗?如果是,怎么办? 还有其他方法可以实现吗?

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?

推荐答案

,您必须使用 https://github. com/juliangruber/keypair

然后将其导入角度分量,例如

then import it in angular component like

import * as keypair from 'keypair';

并使用库方法

const pubprivkey = keypair();
console.log(pubprivkey);

它将返回RSA公钥和私钥的对象

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' }

这篇关于如何使用angular2在客户端生成rsa密钥对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆