diff --git a/lib/internal/crypto/util.js b/lib/internal/crypto/util.js index 6746f2a66c818a..c8a1f9e927ec6b 100644 --- a/lib/internal/crypto/util.js +++ b/lib/internal/crypto/util.js @@ -55,13 +55,13 @@ function getDefaultEncoding() { // This is here because many functions accepted binary strings without // any explicit encoding in older versions of node, and we don't want // to break them unnecessarily. -function toBuf(str, encoding) { - if (typeof str === 'string') { - if (encoding === 'buffer' || !encoding) +function toBuf(val, encoding) { + if (typeof val === 'string') { + if (encoding === 'buffer') encoding = 'utf8'; - return Buffer.from(str, encoding); + return Buffer.from(val, encoding); } - return str; + return val; } const getCiphers = cachedResult(() => filterDuplicateStrings(_getCiphers()));