如何获得与 Linux 加密和盐输出相同的结果?



我在 Ubuntu 机器上使用以下命令"openssl passwd -crypt - salt pass book"来生成一个加盐密码。

输出由什么哈希组成?例如SHA-512,MD5等。另外,我想知道它是如何构成的。例如,它是通过将"存折"一起散列而成的吗?

我需要有关使用什么哈希/算法来生成我看到的输出的更多信息。

谢谢

使用-crypt算法时,openssl passwd应用程序提供的结果似乎与 Linux/Unixcrypt()函数提供的结果相同。您可以使用以下(快速(代码片段来验证这一点:

#include <crypt.h>
#include <stdio.h>
int main(
int argc,
char **argv)
{
char *key = argv[1];
char *salt = argv[2];
char *enc = crypt(key, salt);
printf("key = "%s", salt = "%s", enc = "%s"n",
key ? key:"NULL", salt ? salt:"NULL", enc ? enc:"NULL");
}

结果:

$ ./main book pass
key = "book", salt = "pass", enc = "pahzZkfwawIXw"
$ openssl passwd -crypt -salt pass book
pahzZkfwawIXw

crypt()函数的确切细节似乎在其 OSX 手册页中得到了最清楚的解释,特别是:

Traditional crypt:
The first 8 bytes of the key are null-padded, and the low-order 7 bits of each character is
used to form the 56-bit DES key.
The salt is a 2-character array of the ASCII-encoded salt.  Thus, only 12 bits of salt are
used.  count is set to 25.
Algorithm:
The salt introduces disorder in the DES algorithm in one of 16777216 or 4096 possible ways
(ie. with 24 or 12 bits: if bit i of the salt is set, then bits i and i+24 are swapped in
the DES E-box output).
The DES key is used to encrypt a 64-bit constant, using count iterations of DES.  The value
returned is a null-terminated string, 20 or 13 bytes (plus null) in length, consisting of
the salt, followed by the encoded 64-bit encryption.

最新更新