使用CryptoPP生成随机散列sha1 [英] Using CryptoPP to generate random hashes sha1

查看:544
本文介绍了使用CryptoPP生成随机散列sha1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用CryptoPP生成一个随机散列,使用SHA1。在分钟我有:

I need to generate a random hash using CryptoPP, using SHA1. At the minute 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

任何人都可以帮助我得到这个工作?有一个更简单的方法来执行这个使用这个库?我是使用Crypto ++的新手,所以所有的帮助将非常感激。

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.

谢谢。

推荐答案

只要正确而仔细地指定命名空间:

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))));
}

这篇关于使用CryptoPP生成随机散列sha1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆