Friday 28 February 2020

node-rsa error: incorrect data or key

I have the code :const net = require('net')const NodeRSA = require('node-rsa')​const key = new NodeRSA({b: 512})const key2 = new NodeRSA({b: 512})key2.setOptions({encryptionScheme: 'pkcs1'});key.setOptions({encryptionScheme: 'pkcs1'});​const server = net.createServer(socket => {socket.on("data", data => {key.importKey({n: Buffer.from(data, 'hex'),e: 65537,}, 'components-public');socket.write(key.encrypt(data, 'base64'))console.log("recieved key:", data);})socket.on("error", (err) => {console.log(err.stack)})})server.listen(8080)​const client = new net.Socket()client.connect(8080, "localhost", () => {client.write(key2.exportKey('components-public').n)console.log("sent key:", key2.exportKey('components-public').n);})client.on("data", data => {console.log(key2.decrypt(data, "utf8"));})However when I run this program I get the error:Error: Error during decryption (probably incorrect key). Original error: Error: Incorrect data or keyI assume I'm doing something wrong but I can't figure out what. Does anyone see what my problem is?

Submitted February 28, 2020 at 02:44PM by Totally_Oztralian

No comments:

Post a Comment