diff --git a/index.js b/index.js index 0c25d8f..c292ad2 100644 --- a/index.js +++ b/index.js @@ -118,11 +118,14 @@ module.exports = { * @param {Str} encode [hex/base64] */ md5(str, encode) { - if (typeof str !== 'string' && typeof str !== 'number') { + if (typeof str === 'number') { + str += '' + } + if (typeof str !== 'string' && !Buffer.isBuffer(str)) { return str } - return this.hash('md5', str + '', encode) + return this.hash('md5', str, encode) }, /** @@ -144,11 +147,14 @@ module.exports = { * @param {Str} encode [hex/base64] */ sha1(str, encode) { - if (typeof str !== 'string' && typeof str !== 'number') { + if (typeof str === 'number') { + str += '' + } + if (typeof str !== 'string' && !Buffer.isBuffer(str)) { return str } - return this.hash('sha1', str + '', encode) + return this.hash('sha1', str, encode) }, /** @@ -170,11 +176,14 @@ module.exports = { * @param {Str} encoding [hex/base64] */ sha256(str, encoding) { - if (typeof str !== 'string' && typeof str !== 'number') { + if (typeof str === 'number') { + str += '' + } + if (typeof str !== 'string' && !Buffer.isBuffer(str)) { return str } - return this.hash('sha256', str + '', encoding) + return this.hash('sha256', str, encoding) }, /** diff --git a/package.json b/package.json index b82830d..d09fd31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "crypto.js", - "version": "1.1.4", + "version": "1.1.5", "description": "原生crypto加密模块的二次封装,简化常用加密函数的使用", "keywords": [ "md5",