有人可以帮我解决这个问题吗?
TypeError: Salt must be a buffer
at TypeError (native)
at pbkdf2 (crypto.js:579:20)
at Object.exports.pbkdf2Sync (crypto.js:570:10)
这是功能:
function hash (input, salt) {
// How do we create a hash?
var hashed = crypto.pbkdf2Sync(input, salt, 10000, 512, 'sha512');
return ["pbkdf2", "10000", salt, hashed.toString('hex')].join('$');
}
这就是我发送论据的方式:
var dbString = rows[0].password;
var salt = dbString.split('$')[2];//here i am taking the 2nd column value from a table with 3 columns
var hashedPassword = hash(new Buffer(password, 'binary'), salt); // then passing it to the function hash
答案 0 :(得分:0)
请按照错误消息:salt必须是Buffer
。
把它扔进Buffer()
,我不知道细节,但根据你写的代码,它应该是这样的:
return ["pbkdf2", "10000", new Buffer(salt, 'binary'), hashed.toString('hex')].join('$');