使用Crypto ++生成SHA1随机哈希

Mea*_*ell 4 c++ hash crypto++

我需要使用使用SHA1的Crypto ++生成随机哈希.目前我有:

#include <cryptopp/sha.h>
#include <cryptopp/filters.h>
#include <cryptopp/hex.h>

...

CryptoPP::SHA1 sha1;
string source = "Hello";  //This will be randomly generated somehow
string hash = "";
StringSource(source, true, new HashFilter(sha1, new HexEncoder(new StringSink(hash))));
Run Code Online (Sandbox Code Playgroud)

当我来编译时,我收到以下错误报告:

error: expected type-specifier before 'HashFilter'
error: expected ')' before 'HashFilter'
error: 'StringSource' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)

谁能帮助我让这个工作?有没有一种更简单的方法来使用这个库执行此操作?我是使用Crypto ++的新手,所以非常感谢所有的帮助.

谢谢.

Ker*_* SB 8

只需正确而仔细地指定您的命名空间:

#include <cryptopp/sha.h>
#include <cryptopp/filters.h>
#include <cryptopp/hex.h>

#include <string>

int main()
{
  CryptoPP::SHA1 sha1;
  std::string source = "Hello";  //This will be randomly generated somehow
  std::string hash = "";
  CryptoPP::StringSource(source, true, new CryptoPP::HashFilter(sha1, new CryptoPP::HexEncoder(new CryptoPP::StringSink(hash))));
}
Run Code Online (Sandbox Code Playgroud)

  • 谢谢!cryptopp文档没有**例子. (6认同)
  • 文档不是一个合适的地方,因为它是一个 API 参考(你说的是主页顶部的链接,对吧?)。试试 [Crypto++ Wiki](http://www.cryptopp.com/wiki/Main_Page)。特别是[样本类别](http://www.cryptopp.com/wiki/Category:Sample)。 (2认同)