【问题标题】:Using Crypto++ to generate random hashes with SHA1使用 Crypto++ 使用 SHA1 生成随机哈希
【发布时间】:2011-08-08 11:46:40
【问题描述】:

我需要使用 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++ 的新手,因此我们将不胜感激。

谢谢。

【问题讨论】:

    标签: c++ hash crypto++


    【解决方案1】:

    只需正确且仔细地指定您的命名空间:

    #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 文档有 no 个示例。
    • 文档不是一个合适的地方,因为它是一个 API 参考(你说的是主页顶部的链接,对吧?)。试试Crypto++ Wiki。特别是Sample Category.
    猜你喜欢
    • 2011-11-20
    • 2012-03-13
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    • 2022-12-05
    • 1970-01-01
    • 2014-02-26
    相关资源
    最近更新 更多