简体   繁体   English

C crypt()在md5模式下无法正常工作?

[英]C crypt() not working correctly on md5 mode?

I'm using the crypt() function for the first time in c. 我在c中第一次使用crypt()函数。 I'm just running some initial tests, so none of this is actually going to be used, the constant salt value in particular. 我刚刚运行了一些初始测试,因此实际上并没有使用这些测试,特别是恒定的盐值。 :) :)

I run the following code: 我运行以下代码:

crypt(password, "$1$k7de83ka7");

From my understanding of the crypt docs, this provided salt value should specify that crypt() run in MD5 mode, which will produce a hash of the format "$1$". 根据我对crypt文档的理解,这个提供的salt值应该指定crypt()在MD5模式下运行,这将产生格式为“$ 1 $”的哈希。 The $1$ specifies the value was hashed with MD5. $ 1 $指定使用MD5进行哈希处理的值。 That's how I understand it should work. 这就是我理解它应该工作的方式。

However, when I test the above code, the value returned is "$1ciFuWRySk3A", so it seems to be missing one of the '$' chars. 但是,当我测试上面的代码时,返回的值是“$ 1ciFuWRySk3A”,所以它似乎缺少一个'$'字符。 Am I doing something wrong to cause this problem? 我做错了导致这个问题吗?

crypt(password, "$1$k7de83ka7");

I don't think you're calling crypt correctly, from the man page: 我不认为你正在从手册页正确地调用crypt

If salt is a character string starting with the characters "$id$" followed by a string terminated by "$" : $id$salt$encrypted 如果salt是以字符“$ id $” 开头的字符串,后跟以“$”结尾的字符串$ id $ salt $ encrypted

Then id identifies the encryption method. 然后id标识加密方法。

And you shouldn't expect it to return a string containing $ (not necessarily) 你不应该期望它返回一个包含$的字符串(不一定)

On success, a pointer to the encrypted password is returned. 成功时,将返回指向加密密码的指针。 On error, NULL is returned. 出错时,返回NULL。

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

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