-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example for crypto publicKey signing in Browser and privateKey decryption in node #25589
Comments
It's unclear to me what API you are referring to. Can you be more specific as to what is and isn't clear to you in the existing examples? |
I had a bigger write up I removed when I made some progress, but I will attempt to document some help for others and ultimately a documentation update I'm suggestion. This is about getting a public key to the browser so it can send a message back that can be undone with the private key so as a-typical as it gets for cryptography, and yes generateKeyPairSync is the first step on server side. I took the documented example and have been able to change a few settings but I think it should eventually support 384 and 512 in the future [ not just aes-256-*] (it doesn't seem to currently and looking for that info was also elusive, "what ciphers are allowed and compatible how with the browsers side?").
I ultimately send only th publicKey via a websocket connect or what-have-you. It is in the normal form of a openssl generate PEM file at this point so you could alternatively write and load it as a file.
After getting it working I cleaned these bits and bobbins to my liking from the ones I posted here before that are often not so much to my liking. [I was concerned about the SHA-1 but it's a public key so no worries there I suppose.] Next on the client side via SubtleCrypto as crypto I can encrypt and send it back.
Finally back on the server I can decrypt with the private key the encoded message.
So I think that's enough to show what's needed to get one way encryption working. It should be possible to wrap these steps on both sides into something more user friendly and easier. https://nodejs.org/api/crypto.html I am left wondering is there a better cipher that's compatible and other questions about how to tighten the nuts up. I know Chrome won't go 512 but it can do 384 (that might be an Elliptic only issue). |
So, documentation pull requests are always welcome but do keep in mind that the API documentation is reference documentation; it's not supposed to veer off into specific use cases. A short list of ciphers that can be expected to work with modern browsers is probably okay, a tutorial on how to interoperate between Node.js and a browser likely isn't. It might be material for a guide on the website (probably here) but I can't speak to that; you'd have to ask over at https://github.com/nodejs/nodejs.org. I'm going to tentatively close this but let me know if I should reopen. And if you want to send a PR, please do! |
Thanks, i was clueless i needed SHA-1 |
I have been hard pressed to discover an example of how to use a publicKey sent to a Browser to the be able to decrypt in node what was encrypted in the browser with the nodejs crypto generate KeyPair's PublicKey.
It has been difficult being 'subtle' in the nuances of which type of encryption to use and the impossibility of seeing what it is as it's encrypted and doesn't seem to carry probable information about how it was done etc.
The text was updated successfully, but these errors were encountered: