top | item 10186651

(no title)

jlank | 10 years ago

I ran into this issue, I couldn't encrypt really large strings so I chunked the plain text. Not sure why that is the case. I would consider doing something like what you suggest, though I'm not sure exactly how I'd implement it. If you're interested in showing me how, I'd love to collaborate on some code with you (start an issue! https://github.com/sadasystems/private-message/issues)

discuss

order

jlank|10 years ago

after reading more comments, I now have a better idea of how to achieve this. thanks again!

hardwaresofton|10 years ago

Hey no problem! Should I still open that issue? Seems like you have one made already (https://github.com/sadasystems/private-message/issues/5).

I ended up doing this for a project that I wanted to have use RSA for large chunks of data, for sending it was:

1. Generate random AES cipher key (I used a 16 byte key) using any available secure rng (it all depends on where the thing gets it's entropy, I think node's crypto.getRandomBytes is supposed to be strong)

2. Pad & Encrypt data with AES

3. Encrypt randomly-generated key with RSA

4. Send the message in an envelope like: {key: <RSA encrypted AES key>, data: <AES encrypted data>}

For me, the devil was in the details -- padding took an especially long time for me to understand and solve (the thing I was working on was cross platform, so ruby->js or python->ruby, and of course not all implementations pad the same way), but once that was solved, most other things were easy. The node part was also particularly troubling because I had to deal with the way to specify encodings in node, which was kind of confusing (I spent a lot of time messing with base64/binary encoding and having my terminal start showing gibberish when I tried to print binary data)

I don't have access to that code now (I actually wrote it in order to get around the fact that internal networks at a certain company I used to work at didn't have a custom rootCA/support TLS properly), otherwise I'd just post it.

Would love to help with the implementation though