如何生成加密的密码字符串(如 /etc/shadow 中所示)?
我试图模仿 /etc/shadow 中出现的密码字符串的创建。
这是我到目前为止所得到的,但是当我使用相同的密码和相同的盐时,加密的密码不匹配。
5000 轮是 crypt 的标准,所以我也使用了它,但我不知道我到底在哪里犯了错误:
我在 Perl 中这样做,这是相关的部分:
($pass, $salt) = @ARGV;
unless(defined($salt)) {
$salt = MIME::Base64::encode(random_bytes(12), '');
}
for $i (1 .. 4999) {
$pass = Digest::SHA::sha512($salt, $pass);
}
say "";
print '$6$', $salt, '$', Digest::SHA::sha512_base64($salt, $pass), "\$\n";
I'm trying to mimic the creation of password strings as they appear in /etc/shadow.
This is what I've got so far, but the encrypted passwords don't match, when I use the same password and the same salt.
5000 rounds is standard for crypt, so I used that as well, but I don't see where exacly I made a mistake:
I'm doing this in Perl, this is the relevant porion:
($pass, $salt) = @ARGV;
unless(defined($salt)) {
$salt = MIME::Base64::encode(random_bytes(12), '');
}
for $i (1 .. 4999) {
$pass = Digest::SHA::sha512($salt, $pass);
}
say "";
print '$6
, $salt, '
, Digest::SHA::sha512_base64($salt, $pass), "\$\n";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
加密算法涉及的内容远不止重新哈希 5,000 次:
The crypt algorithm involves a lot more than just re-hashing 5,000 times: