On Tue, Sep 11, 2012 at 9:42 AM, Paulina Budzoń <paulina.bud...@gmail.com> wrote: > Hello everyone, > > Recently I've upgraded my node to v0.8.8 and I encountered this strange > error (I'm not sure if it was present in previous node versions, though). > I have two functions for crypting and decrypting data in my application: > > var cc_key = fs.readFileSync(path_to_key_file); > > crypt = function(val){ > var c = crypto.createCipher('aes256', cc_key.toString()); > c.update(val, 'utf8'); > return c.final('hex') > } > > decrypt = function(val){ > var c = crypto.createDecipher('aes256', cc_key.toString()); > c.update(val, 'hex'); > return c.final('utf8'); > } > > Both work just fine, unless I try to crypt and decrypt strings longer than > 15 characters. > > For example, doing: > > var a = crypt("123456789012345"); > console.log(decrypt(a)) > > works perfectly. > But doing: > > var a = crypt("1234567890123456"); > --- in here a = "694e42d3af6bd12b6fb6d165ca702e30" - so it's not empty and > seem to be ok --- > console.log(decrypt(a)); > > Throws: TypeError: DecipherFinal fail. > > I'm not sure if I'm doing something wrong or there is a bug in crypto module > in node? I looked over the internet and it seems like a lot of people have > similar problems, but no-one knows the answer why is this happening.
You need to concatenate the return values of update() and final(), both when encrypting and decrypting. -- 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 nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en