Note that there are some explanatory texts on larger screens.

plurals
  1. POAES - Encryption with Crypto (node-js) / decryption with Pycrypto (python)
    primarykey
    data
    text
    <p>I'm writing this question + answer because I struggled a lot (maybe because of a lack of experience), got lost in many different ways of encrypting/decrypting things with node or python.</p> <p>I thought maybe my case could help people in the future.</p> <p>What I needed to do:</p> <ul> <li>Get data from a form, encrypt them using Crypto (node-js)</li> <li>Pass the encrypted data in Python and decrypt it using PyCrypto.</li> </ul> <p>I chose to use the AES encryption.</p> <p>Here is how I started (I'm not gonna go through everything I tried):</p> <ul> <li><p>I followed the example at the end of <a href="http://docs.nodejitsu.com/articles/cryptography/how-to-use-crypto-module" rel="nofollow noreferrer">this page</a></p> <p>Which gave in my case:</p> <p>(this might be a very bad mix between javascript and coffeescript)</p> <pre><code>crypto = require "crypto" [...] key = "mykeywhatever" cipher = crypto.createCipher('aes192', key) cipher.update('string i want to encode', 'binary', 'hex') encoded_string = cipher.final('hex') [...] </code></pre> <p>This worked pretty fine to encode my string.</p></li> <li><p>Then I wrote my python script to decrypt this string, using the readme on <a href="https://github.com/dlitz/pycrypto" rel="nofollow noreferrer">PyCrypto's github's page</a>:</p> <pre><code>from Crypto.Cipher import AES [...] my_string = data_coming_from_rabbitmq obj = AES.new('mykeywhatever', AES.MODE_CBC) obj.decrypt(ciphertext) [...] </code></pre> <p>This obviously didn't work: in the readme there is an IV but since I didn't gave one in the node script, why would I give one in the python one?</p></li> </ul> <p>After more googling, I learnt that node's Crypto uses OpenSSL, while PyCrypto apparently doesn't. So I looked into that and found those pages:</p> <ul> <li><a href="https://stackoverflow.com/questions/8806481/how-can-i-decrypt-something-with-pycrypto-that-was-encrypted-using-openssl">How can I decrypt something with PyCrypto that was encrypted using OpenSSL?</a></li> <li><a href="https://stackoverflow.com/questions/5345719/is-aes-the-same-in-libraries-pycrypto-node-js-crypto">Is AES the same in libraries PyCrypto &amp; Node.JS Crypto</a></li> <li>and a lot more...</li> </ul> <p>So things got complicated, no one is doing the same thing to decrypt data, I got lost, and asked for help.</p> <p>The answer is what my coworker and I came up with (well, mostly my corworker).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload