Using cryptographic streams in C++

后端 未结 2 2040
感情败类
感情败类 2021-01-06 19:11

I\'d like to use some cryptographic operations (mainly integrty check hashsums). However I have problems with finding documentations of doing operations of such form:

<
相关标签:
2条回答
  • 2021-01-06 19:48

    crypto++'s FileSource class takes std::istream& in the constructor, so it seems that you are done.

    FileSource (std::istream &in, bool pumpAll, 
        BufferedTransformation *attachment=NULL)
    

    EDIT

    if you are asking how to use a hash function on istream in cryptopp, here's a sample taken from cryptopp wiki, modified by me for use with istream:

    #include "sha.h"
    #include "files.h"
    
    std::string digest;
    
    CryptoPP::SHA256 hash;
    
    CryptoPP::FileSource(in, true,   // true here means consume all input at once 
       new CryptoPP::HashFilter(hash,
             new CryptoPP::StringSink(digest)));
    
    std::cout << digest << std::endl;
    

    This will read the stream in until eof, pass it through a hash filter and finally the result will enf up in the digest string.

    0 讨论(0)
  • 2021-01-06 20:00

    Implement your own istream using crypto++.

    0 讨论(0)
提交回复
热议问题