【问题标题】:How do I generate an encrypted password string, as it is in /etc/shadow?如何生成加密的密码字符串,就像它在 /etc/shadow 中一样?
【发布时间】:2010-09-24 11:26:28
【问题描述】:

我正在尝试模仿 /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";

【问题讨论】:

    标签: cryptography sha512 passwd cryptographic-hash-function


    【解决方案1】:

    crypt 算法涉及很多,不仅仅是重新散列 5,000 次:

    【讨论】:

    • 是的,我期待这样的事情。谢谢,我会通读它并接受它是否是我正在寻找的。​​span>
    • 文档说:“2.密码字符串添加到摘要A。3.盐字符串添加到摘要A。”这是否意味着,首先我将盐附加到密码字符串?如果是这样,那将是 MD5 的另一种方式,它在密码前加上盐。
    • 好的,我到了那里,我还与eglibc.org/cgi-bin/viewcvs.cgi/branches/eglibc-2_9/libc/crypt/… 进行了交叉检查,有趣的是,有一些文档错误...我不太明白最后一部分,他在哪里制作 Base64 ,这是颠倒的字节顺序吗?
    【解决方案2】:
    perl -e 'print crypt("qwerty", "\$6\$somesalt\$")'
    

    【讨论】:

      猜你喜欢
      • 2020-09-17
      • 2023-01-25
      • 1970-01-01
      • 1970-01-01
      • 2020-09-23
      • 2012-08-05
      • 1970-01-01
      • 2011-12-07
      • 1970-01-01
      相关资源
      最近更新 更多