2017-05-17 103 views
5

我目前正在尝试使用NodeJS来加密静态数据,我已经阅读过createCipher不是recommended的Node API文档。Nodejs createCipher vs createCipheriv

crypto.createCipher的实现()导出使用 OpenSSL的功能EVP_BytesToKey与摘要算法设置为MD5, 一次迭代,并且没有盐键。由于同一密码始终创建相同的密钥,因此缺少盐分允许字典攻击 。低迭代次数和非密码安全散列算法允许非常快速地测试密码 。

与OpenSSL的建议,而不是使用 PBKDF2线EVP_BytesToKey建议开发商导出密钥和自己使用crypto.pbkdf2 IV ()和使用crypto.createCipheriv() 创建Cipher对象。

createCipher仍然是一种可行且安全的数据加密方式吗?该方法是否应该被视为弃用? 信息充分的攻击者可以解密数据吗?

如果使用createCipheriv的解决方案总是优于createCipher

任何其他细节或建议表示赞赏。

回答

-2

createCipheriv/createDecipheriv当然优选 使用例:

const crypto = require('crypto') function encrypt(text){ var cipher = crypto.createCipheriv('aes-256-cbc', new Buffer('passwordpasswordpasswordpassword'), new Buffer('vectorvector1234')) var crypted = cipher.update(text, 'utf8', 'hex') crypted += cipher.final('hex') return crypted } function decrypt(text){ var decipher = crypto.createDecipheriv('aes-256-cbc', new Buffer('passwordpasswordpasswordpassword'), new Buffer('vectorvector1234')) var dec = decipher.update(text, 'hex', 'utf8') dec += decipher.final('utf8') return dec }

+1

为什么优选? – andrsnn

+0

iv - 代表https://en.wikipedia.org/wiki/Initialization_vector – IvanM