最佳答案
不是内置的。试试 openssl 的加密库。
( https://www.openssl.org/source/ )
( https://github.com/openssl/openssl/blob/master/include/openssl/sha.h )
( https://www.openssl.org/docs/man1.1.0/crypto/SHA1.html )
#include <openssl/sha.h>
int main()
{
const unsigned char str[] = "Original String";
unsigned char hash[SHA_DIGEST_LENGTH]; // == 20
SHA1(str, sizeof(str) - 1, hash);
// do some stuff with the hash
return 0;
}
与 -lssl
链接,这将暗示 -lcrypto
。如果您是静态链接,则可能需要同时链接两者。
关于c++ - 是否有一个简单的 C 或 C++ 函数来计算字符串的 sha1 哈希?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6934232/