C++ 在C+中使用加密流+;

C++ 在C+中使用加密流+;,c++,cryptography,crypto++,C++,Cryptography,Crypto++,我想使用一些加密操作(主要是整数检查哈希和)。但是,我在查找此类操作的文档时遇到问题: 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; } 它可能是不同

我想使用一些加密操作(主要是整数检查哈希和)。但是,我在查找此类操作的文档时遇到问题:

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;
}
它可能是不同的库,只要它a)与GPL-3兼容b)在GNU/Linux上工作

PPS。我不坚持密码+ +,但是我希望有类似于流的行为,与其他C++库互操作。

< P>使用CuthOp++.< /P> < Pyto++类的构造函数中使用<代码> STD::istRAM&,似乎你已经完成了。
FileSource (std::istream &in, bool pumpAll, 
    BufferedTransformation *attachment=NULL)
编辑

如果您询问
如何在cryptopp
中的istream上使用哈希函数,下面是一个示例,由我修改用于
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;
#包括“sha.h”
#包括“files.h”
字符串摘要;
CryptoPP::SHA256散列;
CryptoPP::FileSource(in,true,//true)在这里表示一次使用所有输入
新的CryptoPP::HashFilter(哈希,
新的CryptoPP::StringSink(摘要));

std::我可以考虑一下,但我怀疑以前可能有人做过。实际上,您实现了自己的istreambuf,而不是自己的istream.LInk被破坏了。但是我不能像在std::istream上那样在过滤后的日期进行操作。@Maciej Piechotka:那么,我认为你的问题不清楚。您不是在问如何在流上使用cryptopp吗?在您的示例中,您使用
std::istream&
。也许您在问如何在流上使用cryptopp的哈希函数?请参阅我对答案的编辑。@davka:我在问如何从cryptopp获取std::istream。@Maciej Piechotka:您的意思是以流的形式获取cryptopp输出吗?在您开始实现自己的流之前,我看到了两个选项:1)将
FileSink
iostream
一起使用,让cryptopp写入,然后将其倒带,然后将其作为
istream
传递到另一个库;2) 使用
StringSink
并使用它写入的字符串创建一个
stringstream
,并将其传递出去。@davka:但是它假设我知道散列部分的长度或从一开始就读取整个流,并且它不依赖于散列内容。