RSA encryption text/message using our PublicKey - JavaScript or ReactJS

1.1k Views Asked by At

What I have to do is encrypt a small message through a public key. I have the public key but I can't encrypt any messages. I have tried with JSEncrypt, encrypt-rsa, hybrid-crypto-js, NodeRSA and crypto. Can´t encrypt message.

The key is something like

      let keyData = `-----BEGIN PUBLIC KEY-----MIIBCgKCAQEAzK1MF/...-----END PUBLIC KEY-----`

The closest to getting anything was through 'NodeRSA', which when doing key.importkey(keyData, 'pkcs8'), returns an error "InvalidAsn1Error: encoding too long"

Can someone give me a hand?


My code is:

import NodeRSA from 'node-rsa';
const key = new NodeRSA();
let keyData = `-----BEGIN PUBLIC KEY-----MIIBCgKCAQEAzK1MF/...-----END PUBLIC KEY-----`
key.importKey(keyData, 'pkcs8');

I stopped here because you gave me the mistake.

0

There are 0 best solutions below