Note that there are some explanatory texts on larger screens.

plurals
  1. POAES-256-CBC with Digest from Ruby to NodeJS
    primarykey
    data
    text
    <p>I am hoping someone can shed some light on a problem that has been vexing me for the last few hours.</p> <p>I am trying to decode a string that has been encoded in Ruby thus:</p> <pre><code>#!/usr/bin/env ruby require 'base64' require 'openssl' require 'openssl/cipher' require 'openssl/digest' aes = OpenSSL::Cipher::Cipher.new('aes-256-cbc') aes.encrypt aes.key = Digest::SHA256.digest('IHazSekretKey') p Base64.encode64( aes.update('text to be encrypted') &lt;&lt; aes.final ) </code></pre> <p>Executing the above spits out: "3P86KyOrN2QJ/HFxxo3b7kAsxTgpDMMjROUPclsuXj0=\n"</p> <p>I now try to decrypt this string in NodeJS 0.6.17</p> <pre><code>#!/usr/bin/env node var crypto = require('crypto'); function decrypto(toDecryptStr) { var result, encoded = new Buffer(toDecryptStr, 'base64'), decodeKey = crypto.createHash('sha256').update('IHazSekretKey', 'ascii').digest(), decipher = crypto.createDecipher('aes-256-cbc', decodeKey); result = decipher.update(encoded); result += decipher.final(); return result; }; console.log(decrypto('3P86KyOrN2QJ/HFxxo3b7kAsxTgpDMMjROUPclsuXj0=')); console.log(decrypto('3P86KyOrN2QJ/HFxxo3b7kAsxTgpDMMjROUPclsuXj0=\n') </code></pre> <p>The second script yields:</p> <pre><code>nazar@xfce:~/tmp/tst$ ./js_decrypt Å'{ H£V)ÜB Å'{ H£V)ÜB </code></pre> <p>Any help would be very much appreciated as my only remaining option now is to drown myself in a barrel of [Jamerson || Kirin Ichiban] (I'm only kidding)</p> <p>PS there is a similar question on SO <a href="https://stackoverflow.com/questions/7192401/encrypting-data-with-ruby-decrypting-with-node">here</a>, which sadly hasn't yielded any inspiration for my case.</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.
 

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