diff --git a/Readme.md b/Readme.md index 58d3d06..53adccb 100644 --- a/Readme.md +++ b/Readme.md @@ -3,7 +3,7 @@ ## 更新日志 + v3.0.0 - - Node.js 10.0.0之后不再推荐使用`crypto.createCipher()`, 所以 本库的`cipher()`方法, 内部改为调用`cipheriv()` + - Node.js 10.0.0之后不再推荐使用`crypto.createCipher()`, 所以 本库的`cipher()`方法, 内部改为调用`cipheriv()` (Node.js大于10.5.0时, 旧版本的不变) + v2.1.0 - 优化`cipher()`等公钥加密方法的`key`和`iv`的默认值为`crypto.scryptSync('', '', 16)` @@ -252,6 +252,10 @@ crypto.cipher('aes-128-gcm', '123456', 'abcdefg') // authTag: // } +// v3.x 之后, decipher()同理 +crypto.cipher('aes-128-cbc', '123456', {key}) +// 等价于 +crypto.cipheriv('aes-128-cbc', '123456', {key}, EMPTY_IV) // 其中 EMPTY_IV = crypto.scryptSync('', '', 16) ``` diff --git a/package.json b/package.json index 8589bd5..5c17cb8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "crypto.js", - "version": "2.1.0", + "version": "3.0.0", "description": "原生crypto加密模块的二次封装,简化常用加密函数的使用", "keywords": [ "md5", diff --git a/src/helper.mjs b/src/helper.mjs index 6467c15..070196d 100644 --- a/src/helper.mjs +++ b/src/helper.mjs @@ -11,10 +11,10 @@ const AUTH_MODE = [ 'aes-192-ocb', 'aes-256-ocb' ] -// const VERSION = +process.versions.node -// .split('.') -// .slice(0, 2) -// .join('.') +const VERSION = +process.versions.node + .split('.') + .slice(0, 2) + .join('.') // const EMPTY_KEY = crypto.scryptSync @@ -45,9 +45,9 @@ export default { cipher(mode, data, key = EMPTY_KEY, inEncode, outEncode) { // 10.0.0之后, createCipher方法不推荐使用了 - // if (VERSION >= 10.5) { - // return this.cipheriv(mode, data, key, EMPTY_KEY, inEncode, outEncode) - // } + if (VERSION >= 10.5) { + return this.cipheriv(mode, data, key, EMPTY_KEY, inEncode, outEncode) + } let isBuffer = Buffer.isBuffer(data) inEncode = isBuffer ? 'binary' : inEncode || 'utf8' outEncode = outEncode || 'base64' @@ -64,9 +64,9 @@ export default { decipher(mode, data, key = EMPTY_KEY, tag, inEncode, outEncode) { // 10.0.0之后, createCipher方法不推荐使用了 - // if (VERSION >= 10.5) { - // return this.decipheriv(mode, data, key, EMPTY_KEY, tag, inEncode, outEncode) - // } + if (VERSION >= 10.5) { + return this.decipheriv(mode, data, key, EMPTY_KEY, tag, inEncode, outEncode) + } let isBuffer = Buffer.isBuffer(data) inEncode = isBuffer ? 'binary' : inEncode || 'base64'