Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

AES-256-CBC encryption not yielding the same results in node vs. ruby #6218

Closed
scotttam opened this issue Sep 12, 2013 · 2 comments
Closed

Comments

@scotttam
Copy link

This is related to issue #1395 .

In it, cesare created both a ruby and node encryption routines that yielded the same results at this comment #1395 (comment) . I am not seeing the same. When I run the ruby, I do see

Encoded length: 48
Encoded in Base64: ux+Flze2MzL1gvrXVvhmow7SukcIrWfg7MGbWmKvLe1lDoOe5IgaKEahwh1c1Nfm

But when I run the node version, I see:

Encoded length: 47
Encoded in Base64: /R/9/Tf9MzL9/f39Vv1m/Q66Rwj9Z/39/f1aYv0t/WUO/f39/RooRv39HVz9/f0=

I'm using Ruby 1.9.3/2.0 and node v0.10.15.

I'm wondering if something regressed or was there a change that I need to incorporate into the node version that I'm missing?

Ruby Gist found here https://gist.github.com/scotttam/6542931
Node Gist found here: https://gist.github.com/scotttam/6542922

Thanks,

Scott

@ghost
Copy link

ghost commented Sep 12, 2013

@scottam, Since version 0.9.3, default output format for encipher.update and encipher.final methods is "Buffer" format, so use Buffer concat method instead of concatenation string. In previous node versions, default format for those methods was "binary".

1ed4c6 -> crypto: Default to buffers instead of binary strings (isaacs, Fedor Indutny)

Here the corrected script for node v0.10.x: https://gist.github.com/Math-/6545005

@bnoordhuis
Copy link
Member

What @Math- said, Cipher#update() and Cipher#final() return buffers by default now. Either pick a different encoding or use Buffer.concat() to concatenate them. Implicit stringification of the buffer with += doesn't usually produce the expected results.

gibfahn added a commit to ibmruntimes/node that referenced this issue Apr 28, 2016
gibfahn added a commit to ibmruntimes/node that referenced this issue Apr 28, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants