c++ - 是否有一个简单的 C 或 C++ 函数来计算字符串的 sha1 哈希?

标签 c++ encryption hash

Possible Duplicate:
sha1 function in cpp (C++)Hi,

我只是在寻找一个计算字符串的 sha1 哈希并返回结果的函数。

最佳答案

不是内置的。试试 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/

相关文章:

c++ - 帮助双向链表?

C++Concurrency in action :Can the Listing7. 6(使用危险指针的 pop() 实现)真的检测到无法回收的节点吗?

java - 在浏览器中执行jar

android - 生成 Proguarded 签名 APK 问题?

java - 如何在字符移位后读取和打印字符串的整个输入?

ruby-on-rails - 使用 Ruby 计算散列字母的数量?

java - Spark TF-IDF 从哈希中获取单词

c++ - 在 C++ 中说 "promote everything to floating before calculation"的确定性方式

c++ - 在字符串中查找字符时遇到问题

php - 更改密码哈希类型的最有效方法(md5 到 sha1)