![](/img/trans.png)
[英]Node.js crypto.pbkdf2Sync password does not match with python script
[英]using crypto.pbkdf2Sync in node 6 return different hash then node4
我們正在嘗試將當前項目的nodeJS版本(4.2.4)升級到最新版本(6.9.1),並且遇到了這樣的問題,我們在用戶密碼上有一些經過身份驗證的方法,它的功能如下:
return this.password === crypto.pbkdf2Sync(password, this.salt, 10000, 64).toString('base64');
this.password是在節點4.2.4上工作的用戶密碼哈希,而password是用戶輸入,
因為我們升級到節點6.9.1,所以它將停止工作並返回false,而在節點4.2.4中則返回true
我們已經嘗試添加任何摘要選項(因為現在需要),但沒有找到匹配的選項
也許還有更多事情我們應該改變? 有人可以幫忙嗎?
您需要將代碼更改為:
crypto.pbkdf2Sync(password, new Buffer(this.salt, 'binary'), 10000, 64).toString('base64');
從節點6開始,默認鹽不是二進制的
您還需要添加摘要,例如:
crypto.pbkdf2Sync(password, new Buffer(this.salt, 'binary'), 10000, 64, 'DSA-SHA1').toString('base64')
在此處查看API: https : //nodejs.org/api/crypto.html#crypto_crypto_pbkdf2sync_password_salt_iterations_keylen_digest
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.