Comparing version 1.0.1 to 1.1.0
{ | ||
"name": "gcm-stream", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -32,2 +32,3 @@ # aes-gcm | ||
| iv | 初始化向量| 否,如果不传内部会随机, 可以通过 encrypt.getIV | | ||
| withoutIV | 是否自动将 IV 添加到密文前 | 否 | | ||
| ivLength | 初始化向量随机的长度, 默认 12 bytes, 当不传递 iv 时用于自动生成 iv| 否| | ||
@@ -37,3 +38,3 @@ | cipherGCMTypes | gcm 加密类型| 否,默认 aes-256-gcm| | ||
## const encrypt = Encrypt(options) | ||
## const decrypt = Decrypt(options) | ||
@@ -49,5 +50,4 @@ 支持的参数 | ||
注意: 加密解密的 key 要一样, iv 长度和 mac 的长度也很重要,如果约定不是使用 iv 12bytes、macLength 16bytes 的情况下,需要主动的声明长度. | ||
注意: 加密解密的 key 要一样, iv 长度和 mac 的长度也很重要,如果约定不是使用 iv 12bytes、macLength 16bytes 的情况下,需要主动的声明长度. | ||
# 背景 | ||
@@ -54,0 +54,0 @@ |
@@ -7,2 +7,6 @@ /// <reference types="node" /> | ||
interface Options { | ||
/** | ||
* @description 不自动带上 IV 头 | ||
*/ | ||
withoutIV?: boolean; | ||
macLength?: number; | ||
@@ -27,2 +31,3 @@ /** | ||
private ivLength; | ||
private withoutIV; | ||
private iv; | ||
@@ -29,0 +34,0 @@ private key; |
@@ -13,5 +13,6 @@ "use strict"; | ||
this.ivLength = 12; | ||
this.withoutIV = false; | ||
this.isFirst = true; | ||
this.cipherGCMTypes = 'aes-256-gcm'; | ||
const { macLength, ivLength, cipherGCMTypes, key, iv } = options; | ||
const { macLength, ivLength, cipherGCMTypes, key, iv, withoutIV } = options; | ||
if (macLength) { | ||
@@ -28,2 +29,3 @@ this.macLength = macLength; | ||
this.iv = this.create(this.ivLength, iv); | ||
this.withoutIV = Boolean(withoutIV); | ||
this.cipher = (0, crypto_1.createCipheriv)(this.cipherGCMTypes, this.key, this.iv, { | ||
@@ -35,3 +37,6 @@ authTagLength: this.macLength, | ||
if (this.isFirst) { | ||
this.push(this.getIV()); | ||
if (!this.withoutIV) { | ||
// 现在允许不自动在头部带上 IV 的形式了 | ||
this.push(this.getIV()); | ||
} | ||
this.isFirst = false; | ||
@@ -38,0 +43,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22829
329