有角度的RSA库 [英] RSA library with angular

查看:265
本文介绍了有角度的RSA库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我试图在我的应用程序中实现加密。我使用角(角-4)作为前端,节点js用于后端。通过socket.io通过自定义命令进行通信。但是基本上我坚持的是在客户端找到一个适用于RSA加密的库。客户端将首先请求服务器进行RSA公钥。服务器响应密钥,但现在我找不到任何适合使用RSA加密数据的库。我试过了node-rsa。以下是来自'node-rsa'的代码sn

  import *作为NodeRSA; 

@Injectable()

export class SecurityService {
RSA:any
initializeRSA(key:string){
this.RSA =新的NodeRSA();
this.RSA.importKey(key)
console.log(this.RSA.encrypt('Hello World'));
}

但我收到此错误。

 加密时出错。原始错误:TypeError:crypt.createHash不是一个函数
在NodeRSA.webpackJsonp ... / .. / .. / .. / node-rsa / src / NodeRSA.js.module.exports.NodeRSA $ $ encrypt

帮助将非常感激。

解决方案

请在这里找到解决方案Plunker:



JSEncrypt with angular

 链接:https://plnkr.co/edit/sEPK1DcynMphJnGziUVX 




实现


在Angular Project的资产文件夹中添加JSEncrypt Lib javascript文件。
index.html中添加脚本



< script src = jsencrypt.js>< / script>



所以,它可以在所有的组件。



在要使用它的组件文件中声明JSEncrypt。



declare var JSEncrypt:any;



Inside类声明变量



decrypt = new JSEncrypt();



const privatekey =私钥在这里;



const publickey =公钥去这里;



const decryptDataRow = Decreted data string;



this.decrypt.setPrivateKey(privatekey);



this.decryptdata = this.decrypt.decrypt(decryptDataRow);



decryptdata conation result string


Hello I am trying to implement encryption in my application. I am using angular (angular-4) for the frontend and node js for the backend. Communication is done through socket.io through custom commands. But basically what I am stuck at is finding an appropriate library for RSA encryption in client side. client will first request server for an RSA public key. Server responds with key but now I cannot find any library suitable to encrypt data with RSA using this public key. I have tried node-rsa. Following is a code 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'));
    }

But I am receiving this error.

Error during encryption. Original error: TypeError: crypt.createHash is not a function
at NodeRSA.webpackJsonp.../../../../node-rsa/src/NodeRSA.js.module.exports.NodeRSA.$$encrypt

Help would be very much appreciated.

解决方案

Please Find Solution Plunker here:

JSEncrypt with angular

link: https://plnkr.co/edit/sEPK1DcynMphJnGziUVX

I have used JSEncrypt v2.3.0 Lib for same.

Implementation

Add JSEncrypt Lib javascript file in Asset Folder of Angular Project. Add script in index.html

<script src="jsencrypt.js"></script>

So, It will available at all Component.

declare JSEncrypt at your component file where you want to use it.

declare var JSEncrypt: any;

Inside class declare variable

decrypt = new JSEncrypt();

const privatekey = Private Key goes here;

const publickey = Public key goes here;

const decryptDataRow = Decreted data string;

this.decrypt.setPrivateKey(privatekey);

this.decryptdata = this.decrypt.decrypt(decryptDataRow);

decryptdata conation result string

这篇关于有角度的RSA库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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