【问题标题】:Node JS Error: Invalid cipher节点 JS 错误:密码无效
【发布时间】:2018-11-26 17:18:04
【问题描述】:

我正在尝试使用 Bookshelf-encrypted-columns 对我的数据进行 aes 加密,因为我需要密钥和密码。密钥不是问题,但是在创建“密码”时,我在下面收到此错误:

"Error: Invalid cipher: 78c2527b394d0d4016571fea85e40c52"

以下代码需要密码:

bookshelf.plugin(encryptColumns, {
    cipher: getCipher(config.encrypt.aesKey),
    key: config.encrypt.aesKey
});

使用 nodejs crypto createCipheriv 创建密码的函数

function getCipher (key) { 
        // generate initialization vector
        let iv = new Buffer.alloc(16); // fill with zeros

        // encrypt data
        return crypto.createCipheriv('aes-256-cbc', key, iv);
}

有没有创建密码的解决方案?

【问题讨论】:

    标签: node.js encryption bookshelf.js


    【解决方案1】:

    cipher 值应该是描述要使用的算法的字符串,而不是 Cipher 对象的实例。

    有关参考,请参阅the default cipher valuethe value passed to the plugin instantiation call for the unit tests

    在你的代码中,尝试使用这个:

    bookshelf.plugin(encryptColumns, {
        cipher: 'aes-256-cbc',
        key: config.encrypt.aesKey
    });
    

    【讨论】:

    • 这导致另一个错误:错误:错误:0606506D:数字信封例程:EVP_DecryptFinal_ex:Decipher.final (crypto.js:183:26) 处的最终块长度错误
    • 我正在尝试加密用户数据,例如电话号码、电子邮件和信用卡详细信息。
    • 接下来我怀疑是键值。你能提供任何关于它被设置为什么的上下文吗?
    • 例如这是我要插入到 db 中的内容:{ "phone": "4575568512", "device_unique_id": "Manisdf123", "device_name": "dasdasdaddsdsdEdited", "device_model" :“ipadEdited”、“device_type”:“ipadEdited”、“device_token”:“dfsdfsdfsdfsdfsdfdfEdited”、“device_version”:1.1 }
    • 当我尝试插入表时,出现以下错误:TypeError: Cipher data must be a string or a buffer, while fetching data 我得到上述错误,这是在第一条评论中
    猜你喜欢
    • 2021-03-02
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 2020-11-04
    • 2019-09-09
    • 1970-01-01
    • 2017-09-24
    • 1970-01-01
    相关资源
    最近更新 更多