From 4231dab39f8d3769196fefede15e048f3ca09300 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 23 Feb 2013 23:43:52 +0100 Subject: [PATCH] crypto: fix base64 padding regression Commit 9901b69c introduces a small regression where the trailing base64 padding is no longer written out when Cipher#final is called. Rectify that. Fixes #4837. --- lib/crypto.js | 2 +- test/simple/test-crypto.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/crypto.js b/lib/crypto.js index 0033267ceee..224c9da5db0 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -258,7 +258,7 @@ Cipher.prototype.final = function(outputEncoding) { if (outputEncoding && outputEncoding !== 'buffer') { this._decoder = getDecoder(this._decoder, outputEncoding); - ret = this._decoder.write(ret); + ret = this._decoder.end(ret); } return ret; diff --git a/test/simple/test-crypto.js b/test/simple/test-crypto.js index 755201ebdee..291ac504b85 100644 --- a/test/simple/test-crypto.js +++ b/test/simple/test-crypto.js @@ -858,3 +858,10 @@ assertSorted(crypto.getHashes()); var c = crypto.createDecipher('aes-128-ecb', ''); assert.throws(function() { c.final('utf8') }, /invalid public key/); })(); + +// Base64 padding regression test, see #4837. +(function() { + var c = crypto.createCipher('aes-256-cbc', 'secret'); + var s = c.update('test', 'utf8', 'base64') + c.final('base64'); + assert.equal(s, '375oxUQCIocvxmC5At+rvA=='); +})();