使用Crypto++与SHA1生成随机哈希
Using Crypto++ to generate random hashes with SHA1
我需要使用Crypto++生成随机哈希,使用SHA1。现在我有:
#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++的新手,所以所有的帮助都会非常感激。
谢谢。
只需正确且仔细地指定您的名称空间:
#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))));
}
相关文章:
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 使用Qt C++计算类似Git的SHA1哈希
- 如何将这个C++哈希表转换为动态扩展和收缩,而不是使用硬设置的最大值
- 用C++将哈希表写入文件并从文件中恢复
- c++找不到具有相同哈希的无序集合元素
- 哈希文件递归并保存到矢量Cryptopp中
- 对 pair<pair<int,int>pair<int,int unordered_map进行哈希处理>>
- 直接在 unordered_map 的方法中使用哈希,而不是生成哈希的用户定义对象
- 如何为字符串生成唯一但一致的 N 位哈希(小于 64 位)?
- 我的求解(字符串 a、字符串 b)的输出与随机哈希中的预期输出不匹配
- 我可以比朴素哈希表更快地将随机字符串映射到两个类吗?
- 如何生成伪随机 32 字节字符串以用作加密哈希函数中的盐?
- 哈希函数和随机排列
- 如何生成随机种子/哈希以使Rand实际上是随机的
- 如何从 O(1) C++哈希表中随机检索元素
- 如何存储需要随机选择和删除的数据,矢量,哈希表或其他
- 如何散列字符串?我需要把随机字符串转换成整数,放到哈希表中
- 随机访问哈希映射值
- 使用Crypto++与SHA1生成随机哈希