2017-03-09 1 views
1

Ich bin eine Flask-Anwendung auf Knoten migrieren. Ich möchte die gleichen Passwort-Hashes in Node erzeugen wie in Python. Die Hashes stimmen jedoch nicht überein. Warum sind die Ergebnisse anders?Python pbkdf2_hmac vs JavaScript crypto.pbkdf2Sync inkonsistenten Hash

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

Antwort

0

Sie haben Ihr Salz von Hex in node.js zu entschlüsseln:

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