0
function encrypt(encrypted, publicKey) {
    const encrypt = crypto.publicEncrypt(publicKey, Buffer.from(encrypted));
    return encrypt;
}
var ciphertext = this.encrypt("***",key.exportKey('public'))

Use the public and private keys generated by node rsa to encrypt using crypto and public key. How can I solve it?

enter image description here

I tried the conversion between uint8array and buffer, but it's different

President James K. Polk
  • 40,516
  • 21
  • 95
  • 125
李海龙
  • 1
  • 1
  • The output should be available in the question as normal text, properly formatted. You can **additionally** include an image from an IDE if it adds clarity to the question. Please read [Why should I not upload images of code/data/errors when asking a question?](https://meta.stackoverflow.com/q/285551/238704) – President James K. Polk Apr 18 '23 at 15:51
  • With nodejs you don't need `node-rsa` to generate RSA keypair, see `crypto.generateKeyPair[Sync]`. Your question isn't very clear and isn't reproducible at all, but if you are expecting different executions of 'standard' RSA encryption (RSAES-PKCS1-v1_5) or OAEP (the default for `crypto.publicEncrypt`) of the same data with the same keypair to produce the same cryptogram/ciphertext, it doesn't. – dave_thompson_085 Apr 18 '23 at 17:35
  • I have solved the problem. Vue and Node default to different types when dealing with binary data. After using toString to transfer the data, the string can be converted to a buffer on the Node side. I'm sorry, this is my first time on this forum and I behaved very foolishly. I apologize.Thank you very much for your answer. Have a good day. – 李海龙 Apr 19 '23 at 08:40

0 Answers0