4

我需要使用 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))));

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

error: expected type-specifier before 'HashFilter'
error: expected ')' before 'HashFilter'
error: 'StringSource' was not declared in this scope

谁能帮我完成这项工作?使用这个库是否有更简单的方法来执行此操作?我是使用 Crypto++ 的新手,因此将不胜感激所有帮助。

谢谢。

4

1 回答 1

10

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

#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))));
}
于 2011-08-08T12:10:07.783 回答