parent
4617514a7c
commit
3cc8c53a72
|
@ -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: <Buffer c4 a0 3e ab e5 34 a0 ea 25 02 f0 91 06 f7 3b dd>
|
||||
// }
|
||||
|
||||
// v3.x 之后, decipher()同理
|
||||
crypto.cipher('aes-128-cbc', '123456', {key})
|
||||
// 等价于
|
||||
crypto.cipheriv('aes-128-cbc', '123456', {key}, EMPTY_IV) // 其中 EMPTY_IV = crypto.scryptSync('', '', 16)
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "crypto.js",
|
||||
"version": "2.1.0",
|
||||
"version": "3.0.0",
|
||||
"description": "原生crypto加密模块的二次封装,简化常用加密函数的使用",
|
||||
"keywords": [
|
||||
"md5",
|
||||
|
|
|
@ -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('.')
|
||||
|
||||
// <Buffer d7 2c 87 d0 f0 77 c7 76 6f 29 85 df ab 30 e8 95>
|
||||
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'
|
||||
|
|
Loading…
Reference in New Issue