Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The critical missing piece is the IV, which is required when encryption/decryption is to be made across language boundaries as apparently the encrypter will generate a random IV (or something like that - still don't understand how Ruby decrypts the string without an IV.... but then what do I know....), if one is not provided.</p> <p>The following snippets show how to encrypt a string in Ruby and decrypt in NodeJS.</p> <pre><code>#!/usr/bin/env ruby require 'openssl' require 'base64' require 'openssl/cipher' require 'openssl/digest' aes = OpenSSL::Cipher::Cipher.new('aes-256-cbc') aes.encrypt aes.key = Digest::SHA256.digest('IHazSekretKey') aes.iv = '1234567890123456' p Base64.encode64( aes.update('text to be encrypted') &lt;&lt; aes.final ) </code></pre> <p>The above prints: "eiLbdhFSFrDqvUJmjbUgwD8REjBRoRWWwHHImmMLNZA=\n"</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.createDecipheriv('aes-256-cbc', decodeKey, '1234567890123456'); result = decipher.update(encoded); result += decipher.final(); return result; } console.log(decrypto('eiLbdhFSFrDqvUJmjbUgwD8REjBRoRWWwHHImmMLNZA=\n')) </code></pre> <p>The JS script now properly decrypts the string.</p> <p>One unfortunate side effect is that existing encrypted data will need to be decrypted and then re-encrypted with an IV that is then used in the decrypting implementation. </p> <p>A PITA but nonetheless a working solution.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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