Generating a SHA256 hash with Crypto++, using a string as input and output?

后端 未结 3 2034
孤独总比滥情好
孤独总比滥情好 2021-01-31 10:43

I need an example of how to use Crypto++ to generate a SHA256 hash from a std::string and output a std::string. I can\'t seem to figure it out. Everything I\'ve tried gives me i

3条回答
  •  情歌与酒
    2021-01-31 11:01

    This outputs a base64 string using the CryptoPP::Base64Encoder:

    #include "sha.h"
    #include "filters.h"
    #include "base64.h"
    
    std::string SHA256HashString(std::string aString){
        std::string digest;
        CryptoPP::SHA256 hash;
    
        CryptoPP::StringSource foo(aString, true,
        new CryptoPP::HashFilter(hash,
          new CryptoPP::Base64Encoder (
             new CryptoPP::StringSink(digest))));
    
        return digest;
    }
    

提交回复
热议问题