PHP
代码:将PHP代码转换为C(SHA1算法)
<?php
$pass = "12345678";
$salt = "1234";
echo sha1($salt.$pass.$salt);
?>
我C
代码使用OpenSSL的密码库在使用SHA1
:http://www.openssl.org/docs/crypto/sha.html。
#include <openssl/sha.h>
int main()
{
const char str[] = "Original String";
const char salt[] = "1234";
const char pass[] = "12345678";
strcat(str, salt, pass);
unsigned char hash[SHA_DIGEST_LENGTH]; // == 20
SHA1(str, sizeof(str) - 1, hash);
// do some stuff with the hash
return 0;
}
我的问题是,我怎么能修改C
代码的确切同样的事情PHP
代码? 谢谢。
使用'strcat()'连接盐? – Barmar 2014-10-09 12:36:12
@Barmar我不知道C如果你能告诉我该怎么做,我会很感激。 – xwk16479 2014-10-09 12:37:14
不需要。请尝试自己弄清楚,然后我们会帮助您修复它,如果它不起作用。这就是你学习的方式。 – Barmar 2014-10-09 12:39:20