0

I am using node-rsa library in both NodeJS and Angular. node-rsa: https://www.npmjs.com/package/node-rsa

I am trying to encrypt a JSON Array from nodeJS server to be sent Angular where it has to decrypt back to JSON Array, I tried few times with different encoding,no luck. With the below code, no error but array size is 0 when I check at Angular side.

NodeJS:

const NodeRSA = require('node-rsa')
...
app.post('/getMembers', (req, res) => {
 const rsaKey = new NodeRSA({
        b: 512
      });
const rsaKey = new NodeRSA({
          b: 512
        });
        rsaKey.importKey(pkey, "pkcs8-public");

   const membersArray = await mongo_groups_collection.aggregate([{...}]).toArray();

   res.status(200).send({
          list: rsaKey.encrypt(membersArray)
        }).end();
});

Angular: Service Snippet:

this.getMembersList().subscribe((data: any) => {
      console.log("Members List received")
      let arrayData:Array<any> = this.secureService.rsaKey.decrypt(data.list);
      console.log("Members decrypted", arrayData)
});

In the console, it prints "Members decrypted Uint8Array [] members-crud.service.ts:133 " and the length of arrayData is zero.

2
  • What's the output you are getting when trying - console.log("Members decrypted", JSON.parse(arrayData)) Commented Nov 26, 2020 at 4:12
  • 1
    I am trying to get the JSON array back, let me try this and get back Commented Nov 26, 2020 at 14:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.