crypto.createDecipher(algorithm, password[, options])
crypto.createDecipheriv()
。algorithm
<string>password
<string> | <ArrayBuffer> | <Buffer> | <TypedArray> | <DataView>options
<Object>stream.transform
选项- 返回: <Decipher>
创建并返回使用给定的 algorithm
和 password
(键)的 Decipher
对象。
options
参数控制流行为并且是可选的,除非使用 CCM 或 OCB 模式(例如 'aes-128-ccm'
)的密码。
在这种情况下,需要 authTagLength
选项并指定身份验证标签的长度(以字节为单位),请参阅 CCM 模式。
对于 chacha20-poly1305
,authTagLength
选项默认为 16 字节。
这个函数在语义上对于所有支持的密码都是不安全的,并且对于计数器模式(例如 CTR、GCM 或 CCM)的密码有致命的缺陷。
crypto.createDecipher()
的实现使用 OpenSSL 函数 EVP_BytesToKey
派生密钥,摘要算法设置为 MD5,一次迭代,不加盐。
缺少盐允许字典攻击,因为相同的密码总是创建相同的密钥。
低迭代次数和非加密安全散列算法允许非常快速地测试密码。
根据 OpenSSL 建议使用更现代的算法而不是 EVP_BytesToKey
,建议开发人员使用 crypto.scrypt()
自行派生密钥和 IV,并使用 crypto.createDecipheriv()
创建 Decipher
对象。
crypto.createDecipheriv()
instead.algorithm
<string>password
<string> | <ArrayBuffer> | <Buffer> | <TypedArray> | <DataView>options
<Object>stream.transform
options- Returns: <Decipher>
Creates and returns a Decipher
object that uses the given algorithm
and
password
(key).
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 chacha20-poly1305
, the authTagLength
option defaults to 16 bytes.
This function is semantically insecure for all supported ciphers and fatally flawed for ciphers in counter mode (such as CTR, GCM, or CCM).
The implementation of crypto.createDecipher()
derives keys using the OpenSSL
function EVP_BytesToKey
with the digest algorithm set to MD5, one
iteration, and no salt. The lack of salt allows dictionary attacks as the same
password always creates the same key. The low iteration count and
non-cryptographically secure hash algorithm allow passwords to be tested very
rapidly.
In line with OpenSSL's recommendation to use a more modern algorithm instead of
EVP_BytesToKey
it is recommended that developers derive a key and IV on
their own using crypto.scrypt()
and to use crypto.createDecipheriv()
to create the Decipher
object.