crypto.createDecipheriv(algorithm, key, iv[, options])


创建并返回一个使用给定 algorithmkey 和初始化向量 (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 模式。对于 AES-GCM 和 chacha20-poly1305authTagLength 选项默认为 16 字节,如果使用不同长度,则必须设置为相应的值。

【The options argument controls stream behavior and is optional except when a cipher in CCM or OCB mode (e.g. 'aes-128-ccm') is used. In that case, the authTagLength option is required and specifies the length of the authentication tag in bytes, see CCM mode. For AES-GCM and chacha20-poly1305, the authTagLength option defaults to 16 bytes and must be set to a different value if a different length is used.】

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' 编码的字符串、缓冲区TypedArrayDataViewkey 可以选择性地是类型为 secretKeyObject。如果密码不需要初始化向量,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.】

在传递 keyiv 的字符串时,请考虑 将字符串用作加密 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.】