繁体   English   中英

节点 JS 错误:密码无效

[英]Node JS Error: Invalid cipher

我正在尝试使用书架加密列对我的数据进行 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);
}

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

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

作为参考,请参阅默认密码值传递给单元测试的插件实例化调用的值

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM