1

im encrypting data on a ruby app and decrypting on a node server, but im getting some errors, I replicate the ruby code on my node server and notice that this 2 lib are working different

# Node crypto

var cipher = crypto.createCipher("aes256", key);
var key = crypto.createHash("sha512").update("foo", "utf8").digest("hex");
var crypt = cipher.update("bar", "utf8", "base64");
crypt += cipher.final("base64");
return crypt;

Result: BTK+S8ogCW7cK7NlA5RUJw==

# Ruby OpenSSL
cipher = OpenSSL::Cipher::Cipher.new('aes256').encrypt
cipher.key = Digest::SHA512.hexdigest("foo")
encrypted = cipher.update("bar".to_s)
encrypted += cipher.final
return Base64.encode64(encrypted)

Result: fnRH+EczVbJWwrPSITkhuw==

how can i fix this

jtomasrl
  • 1,430
  • 3
  • 13
  • 22
  • Node's `crypto.createCipher()` runs your key through OpenSSL's `EVP_BytesToKey`. See http://stackoverflow.com/a/7788781/893780 – robertklep Feb 28 '13 at 15:10

0 Answers0