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.