crypto.createDecipher(algorithm, password[, options])


创建并返回一个使用给定 algorithmpassword(密钥)的 Decipher 对象。

【Creates and returns a Decipher object that uses the given algorithm and password (key).】

options 参数用于控制流行为,可选,除非使用 CCM 或 OCB 模式的加密(例如 'aes-128-ccm')。在这种情况下,authTagLength 选项是必需的,用于指定认证标签的字节长度,见 CCM 模式。对于 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 chacha20-poly1305, the authTagLength option defaults to 16 bytes.】

此功能在所有支持的密码算法中语义上不安全,对于计数器模式(如 CTR、GCM 或 CCM)的密码算法存在致命缺陷。

crypto.createDecipher() 的实现使用 OpenSSL 函数 EVP_BytesToKey 派生密钥,摘要算法设置为 MD5,迭代次数为 1,并且没有使用盐值。缺乏盐值使得字典攻击成为可能,因为相同的密码总是生成相同的密钥。低迭代次数和非密码学安全的哈希算法使得密码可以被非常快速地测试。

【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.】

根据 OpenSSL 的建议,应该使用更现代的算法来替代 EVP_BytesToKey,建议开发者使用 crypto.scrypt() 自行生成密钥和初始化向量(IV),并使用 crypto.createDecipheriv() 创建 Decipher 对象。

【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.】