Node-forge store rsa.keyPair


I am developing a Ionic app which use node-forge and in the specific I need to generate rsa key pair (forge.pki.rsa.KeyPair) and make sign and verify.

I obtained the key pair and I can sign and verify but I have a problem when I have to store in local storage my KeyPair.

I could convert the PrivateKey into json before the store and then parse the json when I retrieve but there is no way to obtain again a forge.pki.rsa.PrivateKey to use the sign function.

I could convert the PrivateKey into PEM but then when I try to get the privateKey back from the PEM I could just obtain a forge.pki.PrivateKey which doesn’t provide the sign function.

What do you suggest to me?

I’m experiencing the same issue, but it seems to be more about type than anything else. I was able to sign and verify after casting to an pki.rsa.PrivateKey. The line of code looks like:

const privateKey : pki.rsa.PrivateKey  = <pki.rsa.PrivateKey>pki.privateKeyFromPem(user_private_key);

Hopefully this helps someone else…

Why aren’t y’all just using SubtleCrypto?