Reputation: 211
I'm really stuck on this! What i'm trying to do:
Now somehow I get either an undefined DOMException in the browser if I try to do the encryption part with ursa, or I get this error in Node.js when I do the encryption in the browser:
Missing error handler on `socket`.
Error: error:040A1079:rsa routines:RSA_padding_check_PKCS1_OAEP_mgf1:oaep decoding error
at Error (native)
at Object.decrypt (/home/jeroen/projects/crypto-nodebrowser/node_modules/ursa/lib/ursa.js:358:33)
at Socket.<anonymous> (/home/jeroen/projects/crypto-nodebrowser/server.js:34:50)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at Socket.onevent (/home/jeroen/projects/crypto-nodebrowser/node_modules/socket.io/lib/socket.js:330:8)
at Socket.onpacket (/home/jeroen/projects/crypto-nodebrowser/node_modules/socket.io/lib/socket.js:290:12)
at Client.ondecoded (/home/jeroen/projects/crypto-nodebrowser/node_modules/socket.io/lib/client.js:193:14)
at Decoder.Emitter.emit (/home/jeroen/projects/crypto-nodebrowser/node_modules/component-emitter/index.js:134:20)
at Decoder.add (/home/jeroen/projects/crypto-nodebrowser/node_modules/socket.io-parser/index.js:247:12)
I made a minimal code example at https://github.com/jvanveen/crypto-nodebrowser that shows the issue. Any help on this is welcome!
Upvotes: 0
Views: 2442
Reputation: 211
Ok, I finally got it. Openssl has OAEP padding hardcoded using SHA1, so ursa's openssl bindings are not suitable if you want to use RSA-OAEP-256. I couldn't find a way to make this work with node-rsa, but Node-forge is quite straightforward here. Just use something like:
var encrypted = publicKey.encrypt(bytes, 'RSA-OAEP', {
md: forge.md.sha256.create()
});
Upvotes: 0
Reputation: 81
Are you able to tell us both the code you are running and the browser it is running in?
Some browsers may only do RSA-OAEP with SHA-1 but from the brief description you have given it is having issues with the decryption. I think more details are needed.
Upvotes: 0