繁体   English   中英

Python pbkdf2_hmac vs JavaScript crypto.pbkdf2Sync不一致哈希

[英]Python pbkdf2_hmac vs JavaScript crypto.pbkdf2Sync inconsistent hash

我正在将Flask应用程序迁移到Node。 我想在Node中生成与Python中相同的密码哈希值。 但是,哈希不匹配。 为什么结果不同?

import hashlib, binascii    

salt = 'aa'     
input_pwd = '1'   
fromHex_salt = binascii.a2b_hex(salt)    
dk = hashlib.pbkdf2_hmac('sha1', input_pwd.encode('utf-8'), fromHex_salt, 1000, dklen=32)
python_result = binascii.hexlify(dk).decode('utf-8')
const crypto = require('crypto');
const salt = 'aa';
const input_pwd = '1';
const js_result = crypto.pbkdf2Sync(input_pwd, salt, 1000, 32, 'sha1').toString('hex');

您忘记在node.js中解码Hex中的salt:

const crypto = require('crypto');
const salt = 'aa';
const input_pwd = '1';
console.log(crypto.pbkdf2Sync(input_pwd, new Buffer(salt, 'hex'), 1000, 32, 'sha1').toString('hex'));

暂无
暂无

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

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