使用Crypto ++通过SHA1生成随机哈希 [英] Using Crypto++ to generate random hashes with SHA1
本文介绍了使用Crypto ++通过SHA1生成随机哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用SHA1生成一个使用Crypto ++的随机哈希。目前我有:
#include
#include< cryptopp / filters.h>
#include< cryptopp / hex.h>
...
CryptoPP :: SHA1 sha1;
string source =Hello; //这会以某种方式随机生成
string hash =;
StringSource(source,true,new HashFilter(sha1,new HexEncoder(new StringSink(hash))));
当我编译时,出现以下错误报告:
错误:'HashFilter'之前的预期类型说明符
错误:预期')'之前'HashFilter'
错误:'StringSource'was was没有在此范围内声明
任何人都可以帮助我解决这个问题吗?使用这个库有没有更简单的方法来执行此操作?我是使用Crypto ++的新手,所以所有的帮助都将非常感谢。
谢谢。
解决方案
#include< cryptopp / sha.h>
#include< cryptopp / filters.h>
#include< cryptopp / hex.h>
#include< string>
int main()
{
CryptoPP :: SHA1 sha1;
std :: string source =Hello; //这会以某种方式随机生成
std :: string hash =;
CryptoPP :: StringSource(source,true,new CryptoPP :: HashFilter(sha1,new CryptoPP :: HexEncoder(new CryptoPP :: StringSink(hash))));
}
I need to generate a random hash using Crypto++, using SHA1. At the moment I have:
#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))));
When I come to compile, I get the following error reported:
error: expected type-specifier before 'HashFilter'
error: expected ')' before 'HashFilter'
error: 'StringSource' was not declared in this scope
Can anyone help me to get this working? Is there a much simpler way of performing this using this library? I am new to using Crypto++ so all help will be much appreciated.
Thanks.
解决方案
Just specify your namespaces correctly and carefully:
#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))));
}
这篇关于使用Crypto ++通过SHA1生成随机哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文