From 5af78262e76e3d4543943f37069b4ecf7f92d6b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Mon, 8 Oct 2018 12:22:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96md5/sha1/sha256,=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=AF=B9buffer=E5=AF=B9=E8=B1=A1=E6=B1=82=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 21 +++++++++++++++------ package.json | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) 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",