gpt4 book ai didi

node.js - decipher.update 上出现加密错误

转载 作者:太空宇宙 更新时间:2023-11-04 01:02:29 25 4
gpt4 key购买 nike

我正在为 Node 项目编写一个 javascript 模块。

我收到一个非常模糊的错误

protocol\Parser.js:82
throw err;

TypeError: error:0000000:lib(0):func(0):reason(0)
at Decipher.Cipher.update (crypto.js:279:27)

下面是我的 javalogin.js 文件。该错误似乎发生在 decipher.update(rows[i].CC, 'hex', 'utf8'); 行。

我确实得到了一些控制台打印出来。

      console.log('DB UserName:', rows[i].UserName); //returns correct username
console.log('DB CC: ', rows[i].CC); //returns 2bf9kdk02kdnf3dk (correct CC hash on db)

JavaLogin.js:

var mysql = require('mysql');
var crypto = require('crypto');
var sha = require('sha1');


var algorithm = 'aes256'; // or any other algorithm supported by OpenSSL
var key = 'secret';
var cipher = crypto.createCipher(algorithm, key);
var decipher = crypto.createDecipher(algorithm, key);
decipher.setAutoPadding(auto_padding=true);

var db = mysql.createConnection(
{
host : 'host location',
user : 'username',
password : 'password',
database : 'databaseName',
}
);

exports.auth = function(query, callback){

db.query(query, function(err, rows, fields) {

if (err) throw err;

for (var i in rows) {
console.log('DB UserName:', rows[i].UserName);
console.log('DB CC: ', rows[i].CC);

var decrypted = decipher.update(rows[i].CC, 'hex', 'utf8');
decrypted += decipher.final('utf8');
console.log(decrypted);

}

var info = rows;

return callback(null,info);
});
};

exports.add = function(query, callback){

db.query(query, function(err, rows, fields) {

var encrypted = cipher.update('ccnumber', 'utf8', 'hex');
encrypted += cipher.final('hex');

if (err) throw err;

// for (var i in rows) {
// console.log('DB Info:', rows[i].UserName);
// }

var info = rows;

return callback(null,info);
});
};

最佳答案

感谢评论中提供的小而有用的帮助。我就是因为这个才明白的。

在原始帖子中,我试图将 var decipher = crypto.createDecipher(algorithm,key); 设置为全局变量,以便我可以在 JavaLogin.js 中的多个函数中使用它。

如果有人能告诉我如何做到这一点,我将不胜感激。

下面的工作代码部分:

exports.auth = function(query, callback){

db.query(query, function(err, rows, fields) {

if (err) throw err;

for (var i in rows) {
console.log('DB UserName:', rows[i].UserName);
console.log('DB CC: ', rows[i].CC);

var decipher = crypto.createDecipher(algorithm, key); //moved this from the top of the file
var decrypted = decipher.update(rows[i].CC, 'hex', 'utf8');
decrypted += decipher.final('utf8');
console.log("decrypted:" + decrypted);

}

var info = rows;

return callback(null,info);
});
};

关于node.js - decipher.update 上出现加密错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25852328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com