好吧,我轉向sha512_crypt,而不是找到一個名爲sha512crypt-node的節點的好庫。 README本身包含一個Python和Node的例子,正是我所需要的。這是一個關於體力勞動的小例子。使用這些平臺:
的Python:
from passlib.hash import sha512_crypt
orig = "password"
h = sha512_crypt.encrypt(orig)
print("hash", h)
# h for eg. is $6$rounds=100000$5YnTXatKh4b1pLjp$3QQjVIfjrbiTakj.wkaw1woAcFiPRAjJP2U/b3BiGW4m8OvI8x0tgw1bb63dNQWMUl1uYNDBcTO3tWgrJ6eHh1
okay = sha512_crypt.verify(orig, h)
print("verified", okay)
節點:
var sha512crypt = require("sha512crypt-node").sha512crypt;
// origHash is the hash generated by passlib
var origHash = "$6$rounds=100000$5YnTXatKh4b1pLjp$3QQjVIfjrbiTakj.wkaw1woAcFiPRAjJP2U/b3BiGW4m8OvI8x0tgw1bb63dNQWMUl1uYNDBcTO3tWgrJ6eHh1",
parts = origHash.split('$'),
rounds = parts[2],
salt = '$' + parts[1] + '$' + rounds + '$' + parts[3],
password = "password";
var hash = sha512crypt(password, salt);
console.log("verified", hash === origHash);