Using Crypto++ to generate random hashes with SHA1

后端 未结 1 1636
温柔的废话
温柔的废话 2020-12-17 05:23

I need to generate a random hash using Crypto++, using SHA1. At the moment I have:

#include 
#include 
#incl         


        
相关标签:
1条回答
  • 2020-12-17 05:57

    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))));
    }
    
    0 讨论(0)
提交回复
热议问题