我想使用一些加密操作(主要是完整性检查hashsum)。然而,我在查找执行这种形式的操作的文档时遇到了问题:
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。如果a)兼容GPL-3 b)可以在GNU/Linux上运行,那么它可能是不同库
PPS。我并不坚持使用crypto++,但是我希望使用类似于IOStream的行为来实现与其他C++库的互操作性。
发布于 2011-01-12 21:49:31
使用crypto++的Implement your own istream。
发布于 2011-01-13 00:59:25
crypto++的FileSource类在构造函数中接受std::istream&,所以看起来你已经完成了。
FileSource (std::istream &in, bool pumpAll,
BufferedTransformation *attachment=NULL)编辑
如果你在问how to use a hash function on istream in cryptopp,这里有一个取自cryptopp wiki的样本,由我修改后用于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;这将读取流in,直到eof,通过hash过滤器传递它,最后结果将在digest字符串中enf。
https://stackoverflow.com/questions/4669306
复制相似问题