【发布时间】:2016-06-02 05:00:06
【问题描述】:
在 Crpto++ 中,可以轻松地使用管道对输入进行哈希处理。
std::string out;
CryptoPP::SHA256 sha;
CryptoPP::StringSource ss(input,true,
new CryptoPP::HashFilter(sha,
new CryptoPP::HexEncoder(
new CryptoPP::StringSink(out))));
现在为了验证给定消息 x 产生相同的哈希输出,我想使用 HashVerificationFilter。我已经尝试过了,但它不起作用。有人知道正确的语法吗?
const int flags = CryptoPP::HashVerificationFilter::THROW_EXCEPTION | CryptoPP::HashVerificationFilter::HASH_AT_END;
CryptoPP::SHA256 sha;
try
{
CryptoPP::StringSource ss(input + out, true,
new CryptoPP::HashVerificationFilter(sha, NULL , flags));
}
catch(const CryptoPP::Exception& e)
{
std::cerr << e.what() << std::endl;
exit(1);
}
我得到了输出:
HashVerificationFilter: message hash or MAC not valid
【问题讨论】:
标签: c++ cryptography crypto++