节点JS错误:无效密码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了节点JS错误:无效密码相关的知识,希望对你有一定的参考价值。

我正在尝试使用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);
}

是否有创建密码的解决方案?

答案

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
});

以上是关于节点JS错误:无效密码的主要内容,如果未能解决你的问题,请参考以下文章