On 8 October 2012 15:48, James Coglan <[email protected]> wrote:

> I'm trying to implement a crypto system, and want to make sure I'm doing
> something portable, i.e. the ciphertexts I generate can be understood by
> any language with openssl functionality. I have a Ruby program that uses
> AES-256-CBC to encrypt some data, and I want to make sure I can generate
> the same ciphertext using Node.
>
> What mode of operation does crypto.createCipher('aes256') use? I assume
> it's not a bare AES function since it can encrypt arbitrary amounts of
> data, so it must be using a construction like CBC or CTR. Which one does it
> use, and can it be changed by the user?
>

To partially answer my own question: 'aes-256-cbc' is an allowed mode.
There are other modes available according to `openssl enc --help` but not
all of them work in Node.

If you want to set the IV used, you need to use crypto.createCipheriv().
For aes-256-cbc, the key must be 32 bytes, the IV 16. e.g.:

var crypto = require('crypto'),
    key    = '2ea5074bcc33ccbd1cd99341b837fcb4',
    iv     = '0123456789abcdef',
    aes    = crypto.createCipheriv('aes-256-cbc', key, iv);

var cipher = aes.update('The Text', 'utf8', 'hex') + aes.final('hex');
console.log(cipher);

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to