我需要使用使用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 ++的新手,所以非常感谢所有的帮助.
谢谢.
只需正确而仔细地指定您的命名空间:
#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)