I have the following hashed entry in a password file:
$pbkdf2-sha512$25000$K0XonfPe29vbW0up9X5vDQ$3scRqpOxF29.tqPWpKJmcFvpb8/SFtbAiI2UlrM473B3tD.Mw8xzamNaE0KpZApTc7N1stlK/vvdUl9xna6wIA
Now, I know that the password used to generate this entry was "foobar". Per this URL, I also know the following:
- pbkdf2-sha512 identifies the cryptographic hash used to generate the hash.
- 25000 identifies the iterations performed.
- K0XonfPe29vbW0up9X5vDQ is the adapted base64 encoding of the raw salt bytes passed into the PBKDF2 function
- 3scRqpOxF29.tqPWpKJmcFvpb8/SFtbAiI2UlrM473B3tD.Mw8xzamNaE0KpZApTc7N1stlK/vvdUl9xna6wIA is the raw derived key bytes returned from the PBKDF2 function
So my code proceeds from this as follows:
from passlib.utils.binary import ab64_decode
from passlib.hash import pbkdf2_sha512
salt = 'K0XonfPe29vbW0up9X5vDQ'
salt_decoded = ab64_decode(salt)
hashed_string = pbkdf2_sha512.hash('foobar', rounds=25000, salt=salt_decoded)
My problem: I expect hashed_string to always return the same value and to match the password file entry. But instead, I always get the following value for hashed_string:
$pbkdf2-sha512$25000$K0XonfPe29vbW0up9X5vDQ$ekYyFII.tyf0kWX1BBkICleOTCWIjDbKtGQ4iAU/qvGSmWQf.SAcFcJu6ZGwFFQMe4Kws2ngw.pgGaVe7F/I2g
Where am I going wrong?
I've tried various combinations of encoding and decoding values, without success. I would guess that if I knew to derive the salt correctly from the entry in the password file and/or knew how to call pbkdf2_sha512.hash()
correctly, my problem would be solved.