Tuesday, 2 May 2017

How to encrypt a value in Node JS using node-rsa and decrypt the encrypted value using JSEncrypt in Angular JS

The question may be silly. But I don't get any better documentation to solve the problem.

I am developing an app using Node JS/ Express JS in the back end and Angular JS/ JSEncrypt in the Front End.

there is one field in the output JSON of every REST api named totalSales. I want this field to be encrypted when it comes from the backend using node-rsa module. And I am able to decrypt the value using JSEncrypt in the front end.

Front End I want to write code in the manner,

// pseudo code for front end    
this.crypt = new JSEncrypt({ default_key_size: 1024 })
    data['totalSales'] = this.crypt.decrypt(data['totalSales'])

Back end I want to write the code

//pseudo code for back end
 var key = NodeRSA(<some pem string if possible>)

But I get confused about public/ private key. How to do that?



via Anijit

No comments:

Post a Comment