如何生成加密的密码字符串(如 /etc/shadow 中所示)?

发布于 2024-09-24 18:20:42 字数 460 浏览 1 评论 0原文

我试图模仿 /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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

芯好空 2024-10-01 18:20:42

加密算法涉及的内容远不止重新哈希 5,000 次:

The crypt algorithm involves a lot more than just re-hashing 5,000 times:

故人如初 2024-10-01 18:20:42
perl -e 'print crypt("qwerty", "\$6\$somesalt\$")'
perl -e 'print crypt("qwerty", "\$6\$somesalt\$")'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文