简体   繁体   English

无法通过openssl以与crypt,mkpasswd或openssl通过cmdline相同的格式通过openssl获取密码哈希

[英]Cant get password hash via openssl in c same format as crypt, mkpasswd or openssl via cmdline

I need to create a hashed password via the openssl lib in C. Unfortunately, I'm not able to get the expected result 我需要通过C中的openssl库创建一个哈希密码。不幸的是,我无法获得预期的结果

This is the code I`m using: 这是我使用的代码:

unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, "xxx", 3);
SHA256_Update(&sha256, "11111111", 8);
SHA256_Final(hash, &sha256);

for(int i = 0; i < SHA256_DIGEST_LENGTH; i++)
{
    printf("%02x", hash[i]);
}

The output will be 输出将是

57b2e9dd7f27e02ce026c1a40c7685b4658c2dff55e3a9de93186e545d1c4af1 57b2e9dd7f27e02ce026c1a40c7685b4658c2dff55e3a9de93186e545d1c4af1

but i expected 但我期望

EDgBhRzUlXHcobBLtDfoWalyRFoSMnO1/q.s10aKSY7 EDgBhRzUlXHcobBLtDfoWalyRFoSMnO1 / q.s10aKSY7

since this is the output the crypt lib will produce as well as mkpasswd or openssl via shell. 由于这是输出,因此crypt库将通过shell生成mkpasswd或openssl。

See: 看到:

mkpasswd -m sha-256 --salt=11111111 xxx
$5$11111111$EDgBhRzUlXHcobBLtDfoWalyRFoSMnO1/q.s10aKSY7

or 要么

openssl passwd -5 -salt 11111111 xxx
$5$11111111$EDgBhRzUlXHcobBLtDfoWalyRFoSMnO1/q.s10aKSY7

or 要么

printf("%s\n", crypt("xxx", "$5$11111111"));
// also prints $5$11111111$EDgBhRzUlXHcobBLtDfoWalyRFoSMnO1/q.s10aKSY7

I need to get this working with the openssl lib. 我需要使它与openssl库一起使用。 Am I completely wrong with creating the hash and salt, or is this just a dump formatting issue? 创建哈希和盐我完全错了吗,还是仅仅是转储格式问题?

The algorithm is not just a simple SHA256 hash. 该算法不仅是简单的SHA256哈希。

As reference the OpenSSL implementation can be found on github (shacrypt(...)). 作为参考,可以在github (shacrypt(...))上找到OpenSSL实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM