【问题标题】:Is there a header file for sha256?有sha256的头文件吗?
【发布时间】:2014-08-29 15:40:06
【问题描述】:

我使用的是 linux,我只需要一个现有的 sha-256 标头;我尝试了很多代码块,都没有成功。

#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;
} 

填充哈希输入:

0x61626380000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000018

如何添加sha256.h

【问题讨论】:

  • @Niall 这不是我的母语,所以我做错了,谢谢你修复它。

标签: c++ linux header cryptography sha256


【解决方案1】:

不在 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。如果是这种情况,您可以简单地从站点复制/粘贴文件并使用您的项目构建它们。

【讨论】:

  • 我只是初学者,所以我再次对此感到抱歉。 openssl/sha.h:没有它说的这样的文件。我该怎么办?
  • 在linux上你必须安装openssl的开发包。在 Ubuntu 上是sudo apt-get install libssl-dev。这将安装到/usr/include 中,然后可以被编译器找到。不要忘记链接到 ssl 库。
  • 这是您使用的构建环境的问题......因此不在主题范围内。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-07
  • 2015-03-24
  • 1970-01-01
  • 2020-09-27
  • 2019-07-15
相关资源
最近更新 更多