节点JS错误:无效密码

问题描述 投票:1回答:1

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

"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个回答
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
});
© www.soinside.com 2019 - 2024. All rights reserved.