【问题标题】:Python pbkdf2_hmac vs JavaScript crypto.pbkdf2Sync inconsistent hashPython pbkdf2_hmac vs JavaScript crypto.pbkdf2Sync 哈希不一致
【发布时间】:2017-03-09 05:40:31
【问题描述】:

我正在将 Flask 应用程序迁移到 Node.js。我想在 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');

【问题讨论】:

    标签: python node.js flask cryptography hashlib


    【解决方案1】:

    您忘记从 node.js 中的十六进制解码盐:

    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'));

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 2015-03-21
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      • 1970-01-01
      • 2011-05-27
      • 2013-02-26
      相关资源
      最近更新 更多