0

I have a frontend in angular and a backend in C#. I generated a pair of keys (XML format) and I want to use the public key to encrypt some data in the frontend and send it to the backend where I'll decrypt it. However, I couldn't use any of the libraries/modules that I found on the internet. Does anyone know a good library that I can use? If you could also provide an example, it would be great!

Thanks in advance!

Ins
  • 173
  • 1
  • 11

1 Answers1

1

I found node-forge which was suggested here and managed to put it working. For node-forge, I needed to export my public key in the PEM format. For such thing, I used this code and then I loaded the key and encrypted my data just like this (on angular)

let rsa = forge.pki.publicKeyFromPem("-----BEGIN PUBLIC KEY-----"+
    "MIIBI..."+
    "-----END PUBLIC KEY-----");

return window.btoa(rsa.encrypt(data));
Ins
  • 173
  • 1
  • 11