gpt4 book ai didi

c++ - 使用 Crypto++ 通过 SHA1 生成随机哈希

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:25:11 25 4
gpt4 key购买 nike

我需要使用 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))));
}

关于c++ - 使用 Crypto++ 通过 SHA1 生成随机哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6981616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com