top | item 10186697

(no title)

jlank | 10 years ago

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

discuss

order

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