crypto.createDecipheriv(algorithm, key, iv[, options])
algorithm<string>key<string> | <ArrayBuffer> | <Buffer> | <TypedArray> | <DataView> | <KeyObject> | <CryptoKey>iv<string> | <ArrayBuffer> | <Buffer> | <TypedArray> | <DataView> | <null>options<Object>stream.transform选项- 返回:Decipheriv
创建并返回一个使用给定 algorithm、key 和初始化向量 (iv) 的 Decipheriv 对象。
🌐 Creates and returns a Decipheriv object that uses the given algorithm, key
and initialization vector (iv).
options 参数控制流行为,除非使用 CCM 或 OCB 模式(例如 'aes-128-ccm')的密码,否则是可选的。在这种情况下,必须使用 authTagLength 选项,并指定认证标签的字节长度,参见 CCM 模式。对于 chacha20-poly1305,authTagLength 选项默认为 16 字节,如果使用不同的长度,必须设置为不同的值。对于 AES-GCM,在解密时 authTagLength 选项没有默认值,并且 setAuthTag() 将接受任意短的认证标签。此行为已弃用且可能会更改(参见 DEP0182)。
与此同时,应用应设置 authTagLength 选项,或者在将其传递给 setAuthTag() 之前检查实际的认证标签长度。
algorithm 依赖于 OpenSSL,例如 'aes192' 等。在最新的 OpenSSL 版本中,运行 openssl list -cipher-algorithms 将显示可用的加密算法。
🌐 The algorithm is dependent on OpenSSL, examples are 'aes192', etc. On
recent OpenSSL releases, openssl list -cipher-algorithms will
display the available cipher algorithms.
key 是由 algorithm 使用的原始密钥,而 iv 是一个 初始化向量。两个参数都必须是 'utf8' 编码的字符串、缓冲区、TypedArray 或 DataView。key 可以选择性地是类型为 secret 的 KeyObject。如果密码不需要初始化向量,iv 可以为 null。
🌐 The key is the raw key used by the algorithm and iv is an
initialization vector. Both arguments must be 'utf8' encoded strings,
Buffers, TypedArray, or DataViews. The key may optionally be
a KeyObject of type secret. If the cipher does not need
an initialization vector, iv may be null.
在传递 key 或 iv 的字符串时,请考虑 将字符串用作加密 API 输入时的注意事项。
🌐 When passing strings for key or iv, please consider
caveats when using strings as inputs to cryptographic APIs.
初始化向量应该是不可预测的且唯一的;理想情况下,它们将是加密学上随机的。它们不必保密:IV 通常只是被添加到密文消息中而不加密。听起来可能有些矛盾:某些东西必须是不可预测和唯一的,但不必保密;请记住,攻击者不能提前预测某个特定的 IV 会是什么。
🌐 Initialization vectors should be unpredictable and unique; ideally, they will be cryptographically random. They do not have to be secret: IVs are typically just added to ciphertext messages unencrypted. It may sound contradictory that something has to be unpredictable and unique, but does not have to be secret; remember that an attacker must not be able to predict ahead of time what a given IV will be.