Using cryptographic streams in C ++

I would like to use some cryptographic operations (basically integrity checking hashes). However, I am having problems finding documentation on how to execute this form:

bool read(std::istream &in) { hasher hv(in); // Do some operations on hv as if it was std::istream hash_type h = hv.finish (); hash_type h2 = read_hash(in); return h == h2; } 

PS. It may be another library provided that it: a) is compatible with GPL-3; b) runs on GNU / Linux

SFC. I do not insist on crypto ++, but I would like to have behavior similar to IOStream for interacting with other C ++ libraries.

+3
c ++ cryptography crypto ++
source share
2 answers

Deploy your own istream with crypto ++.

0
source share

The crypto ++ FileSource class takes std::istream& in the constructor, so it seems like you're done.

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

EDIT

if you ask how to use a hash function on istream in cryptopp , here is a sample taken from the 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 in stream to eof, pass it through the hash filter, and finally, the result will be included in the digest line.

+6
source share

All Articles