下面的C/C++代码实现利用OpenSSL计算SHA1哈希值
#include <stdio.h>
#include <string.h>
#include <openssl/sha.h>
int main()
{
unsigned const char ibuf[] = "compute sha1";
unsigned char obuf[20];
SHA1(ibuf, strlen((const char * )ibuf), obuf);
int i;
for(i = 0; i < 20; i++)
{
printf("%02x ", obuf[i]);
}
printf("\n");
return 0;
}
gcc -o example_sha example_sha.cpp -lssl -lcrypto
本文介绍了一个简单的C/C++示例程序,该程序利用OpenSSL库来计算字符串“computesha1”的SHA1哈希值,并将结果以十六进制形式输出。

422

被折叠的 条评论
为什么被折叠?



