我使用的是 Linux,我只需要 sha-256 的现有 header ;我尝试了很多代码块,但没有一个起作用。
#include <iostream>
#include "sha256.h"
using namespace std;
int main(int argc, char *argv[])
{
string input = "abc";
string output1 = sha256(input);
cout << "sha256('"<< input << "'):" << output1 << endl;
return 0;
}
填充哈希输入:
0x616263800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000018
如何添加sha256.h
?
最佳答案
不在 STL 中。您可以使用您选择的库(例如 OpenSSL):
#include <openssl/sha.h>
void foo()
{
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, str.c_str(), str.size());
SHA256_Final(hash, &sha256);
}
我猜你的例子来自 here 。如果是这种情况,您只需从网站复制/粘贴文件并使用您的项目构建它们即可。
关于c++ - 有sha256的头文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25544604/