diff --git a/lib/crypto.js b/lib/crypto.js index 4650067fe6d..0cc70ff15a8 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -236,6 +236,7 @@ Hmac.prototype._transform = Hash.prototype._transform; function getDecoder(decoder, encoding) { + if (encoding === 'utf-8') encoding = 'utf8'; // Normalize encoding. decoder = decoder || new StringDecoder(encoding); assert(decoder.encoding === encoding, 'Cannot change encoding'); return decoder; diff --git a/test/simple/test-crypto.js b/test/simple/test-crypto.js index 1d913fe0b54..36f232d6782 100644 --- a/test/simple/test-crypto.js +++ b/test/simple/test-crypto.js @@ -900,3 +900,18 @@ assert.throws(function() { c.update('update'); c.final(); })(); + +// #5655 regression tests, 'utf-8' and 'utf8' are identical. +(function() { + var c = crypto.createCipher('aes192', '0123456789abcdef'); + c.update('update', ''); // Defaults to "utf8". + c.final('utf-8'); // Should not throw. + + c = crypto.createCipher('aes192', '0123456789abcdef'); + c.update('update', 'utf8'); + c.final('utf-8'); // Should not throw. + + c = crypto.createCipher('aes192', '0123456789abcdef'); + c.update('update', 'utf-8'); + c.final('utf8'); // Should not throw. +})();