【发布时间】:2017-12-06 19:46:47
【问题描述】:
您好,我正在尝试在我的应用程序中实现加密。我在前端使用 angular (angular-4),在后端使用 node js。通信是通过 socket.io 通过自定义命令完成的。但基本上我坚持的是在客户端找到一个合适的 RSA 加密库。客户端将首先向服务器请求 RSA 公钥。服务器以密钥响应,但现在我找不到任何适合使用此公钥使用 RSA 加密数据的库。我试过node-rsa。下面是一段代码sn
import * as NodeRSA from 'node-rsa';
@Injectable()
export class SecurityService {
RSA: any
initializeRSA(key: string) {
this.RSA = new NodeRSA();
this.RSA.importKey(key)
console.log(this.RSA.encrypt('Hello World'));
}
但是我收到了这个错误。
Error during encryption. Original error: TypeError: crypt.createHash is not a function
at NodeRSA.webpackJsonp.../../../../node-rsa/src/NodeRSA.js.module.exports.NodeRSA.$$encrypt
非常感谢您的帮助。
【问题讨论】:
-
我不太确定,但您所做的是后端 Javascript,我假设您需要前端 Javascript 库。试试这个github.com/travist/jsencrypt
-
我将它用于我的一个项目npmjs.com/package/crypto-js
-
@Yatinpatel crypto-js 不提供 RSA 加密
-
@theadnangondal 更新链接 jsfiddle.net/ygd8wpq0
标签: node.js angular encryption