Re:Show HN: Encrypted Communication via GitHub Using Node.js...
by jlank on Tuesday September 08, 2015 @12:35PM
(#10186693)
I love this comment. Thank you for putting the time in to proposing a more thorough solution. I will take this (and other) comments into consideration, and make some much needed improvements :)
Re:Show HN: Encrypted Communication via GitHub Using Node.js...
by tptacek on Tuesday September 08, 2015 @01:09PM
(#10186891)
There are a whole bunch of things you're likely to get wrong trying to design your own "hybrid" encryption system. It's not easy. Why not spend some time learning how to break crypto before you start building it?
Re:Show HN: Encrypted Communication via GitHub Using Node.js...
by ryan-c on Tuesday September 08, 2015 @01:27PM
(#10187038)
I agree. There are whole classes of problems that are not at all obvious until one has spent time learning how to break bad crypto. Matasano's challenges[0] (which I think tptacek helped create) are a good start.
Re:Show HN: Encrypted Communication via GitHub Using Node.js...
by jps359 on Tuesday September 08, 2015 @01:21PM
(#10186997)
Do you have any specific resources that you can recommend for learning to break crypto?
Re:Show HN: Encrypted Communication via GitHub Using Node.js...
by kaoD on Tuesday September 08, 2015 @01:25PM
(#10187029)
- Matasano crypto challenges: http://cryptopals.com/
- https://www.crypto101.io/ both the presentation and the book.
I think those are good to begin with.
In encryptMessage.js, the plaintext is split into chunks, and then chunks.forEach encrypts each chunk (via crypto.publicEncrypt) independently, and concatenates the chunks to form the ciphertext, aka ECB mode. You shouldn't use ECB mode with any cipher because it is not semantically secure. This is Crypto 101.
In addition, it's a bit wacky to use RSA encryption on your entire message because RSA operations are slow and you are limited to encrypting messages that are the length of your RSA key (well, minus the padding, which is how this developer arrived at the "split plaintext into 214 byte chunks" workaround).
A better solution (in every way) would be to use a "hybrid" encryption scheme, similar to TLS or GPG. To do this, you would:
1. Generate a random key for use with a symmetric cipher (e.g. AES-256) 2. Encrypt the plaintext with the random key, using a secure block mode (e.g. CBC, CTR) 3. Encrypt the random key with the RSA public key 4. Package those things together and share it on Github
Efficient and secure. Also totally unnecessary (you basically just reinvented a subset of GPG) but that's neither here nor there.