我需要使用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 ++的新手,所以非常感谢所有的帮助。
感谢。
答案 0 :(得分: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))));
}