crypto.createDecipher(algorithm, password[, options])
crypto.createDecipheriv()
。algorithm
<string>password
<string> | <Buffer> | <TypedArray> | <DataView>options
<Object>stream.transform
选项- 返回: <Decipher>
创建并返回使用给定的 algorithm
和 password
(键)的 Decipher
对象。
options
参数控制流的行为,并且是可选的,除非使用 CCM 或 OCB 模式的加密(例如 'aes-128-ccm'
)。
在这种情况下,需要 authTagLength
选项并指定身份验证标签的长度(以字节为单位),请参阅 CCM 模式。
crypto.createDecipher()
的实现使用 OpenSSL 函数 EVP_BytesToKey
派生密钥,摘要算法设置为 MD5,一次迭代,不加盐。
缺少盐允许字典攻击,因为相同的密码总是创建相同的密钥。
低迭代次数和非加密安全散列算法允许非常快速地测试密码。
根据 OpenSSL 建议使用更现代的算法而不是 EVP_BytesToKey
,建议开发人员使用 crypto.scrypt()
自行派生密钥和 IV,并使用 crypto.createDecipheriv()
创建 Decipher
对象。
crypto.createDecipheriv()
instead.algorithm
<string>password
<string> | <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 is used (e.g. 'aes-128-ccm'
). In that case, the
authTagLength
option is required and specifies the length of the
authentication tag in bytes, see CCM mode.
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.