FileSink,StringSink,Filesource,StringSource Crypto ++有什么区别? [英] What is the difference between FileSink, StringSink, Filesource, StringSource Crypto++

查看:273
本文介绍了FileSink,StringSink,Filesource,StringSource Crypto ++有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在读一张图片,加密,然后解密。目标是最终循环,并记录进程完成所需的时间。目前我已经读取了文件,然后加密,加密,根据恢复的数据创建另一个文件。我不需要使用解密的图片制作另一个文件。以前我一直在使用StringSource和StringSink,但这只适用于文本文件。我在如何将图像读取到加密Crypto ++的字符串,并从FileSink和FileSource开始使用。

I am reading in an image, encrypting it, then decrypting it. The goal is to be looping this eventually and recording the time it takes for the process to complete. Currently what I have it reads the file in, then it encrypts it, encrypts it, the creates another file based on the recovered data. I don't need to make another file with the decrypted picture. Previously I had been using StringSource and StringSink, but that only worked for text files. I received some help at How to read an image to a string for encrypting Crypto++ from and started using FileSink and FileSource.

FileSink,StringSink,FileSourcem StringSource之间有什么区别?

What exactly is the difference between FileSink, StringSink, FileSourcem StringSource.

另外,在下面的示例中为什么是否需要设置密码?以前,当我刚刚使用StringSource时,我的字符串密码没有初始化,但是现在我使用FileSource,它需要被初始化才能工作。

Also, in following example, why does cipher need to be set to something? Previously when I was just using StringSource, my string cipher was not initialized, but now that I am using FileSource, it needs to be initialized for it to work.

int main(int argc, char* argv[]) {
    AutoSeededRandomPool prng_blowfish;

    SecByteBlock key_blowfish(Blowfish::DEFAULT_KEYLENGTH);
    prng_blowfish.GenerateBlock( key_blowfish, key_blowfish.size() );

    byte iv_blowfish[ Blowfish::BLOCKSIZE ];
    prng_blowfish.GenerateBlock( iv_blowfish, sizeof(iv_blowfish) );

    string ifilename = "sample_files/1MB.jpg";
    string cipher = "1MB.enc";
    string rfilename = "r1MB.jpg";

    try {

    EAX< Blowfish >::Encryption e_blowfish;
    e_blowfish.SetKeyWithIV( key_blowfish, key_blowfish.size(), iv_blowfish, sizeof(iv_blowfish) );

    std::ifstream ifile(ifilename.c_str(), ios::binary);
    std::ifstream::pos_type size = ifile.seekg(0, std::ios_base::end).tellg();
    ifile.seekg(0, std::ios_base::beg);

    FileSource fs1( ifilename.c_str(), true, new AuthenticatedEncryptionFilter( e_blowfish, new FileSink(cipher.c_str()) ) );

    EAX< Blowfish >::Decryption d_blowfish;
    d_blowfish.SetKeyWithIV( key_blowfish, key_blowfish.size(), iv_blowfish, sizeof(iv_blowfish) );

    FileSource fs2( cipher.c_str(), true, new AuthenticatedDecryptionFilter( d_blowfish, new FileSink( rfilename.c_str() ), AuthenticatedDecryptionFilter::THROW_EXCEPTION ) ); 


    } catch (const Exception& ex) {
        cerr << ex.what() << endl;
    }

    return 0;
}


推荐答案


FileSink,StringSink,FileSourcem StringSource之间的区别究竟是什么。

What exactly is the difference between FileSink, StringSink, FileSourcem StringSource.

源,过滤器和接收器是Crypto ++中管道设计的一部分。来自源的数据流由过滤器转换,然后以水槽结束。

Sources, Filters and Sinks are part of the Pipeline design in Crypto++. Data flows from a source, is transformed by filters, and then ends at a sink.

所有来源都是可互换的。所有过滤器都是可互换的。所有的水槽都是可互换的。例如,要在 StringSink FileSink 之间切换,您需要提供一个文件名为文件接收。否则,它们的操作相同。另一个例子,您可以在没有更改的情况下在 HexEncoder Base64Encoder 之间切换。作为最后一个例子,一个 SocketSource SocketSink 将需要一个IP地址和端口。什么可能(或可能不)需要更改取决于对象。

All sources are interchangeable. All filters are interchangeable. And all sinks are interchangeable. For example, to switch between a StringSink and FileSink, you need to supply a filename with a FileSink. Otherwise, they operate the same. As another example, you can switch between a HexEncoder and Base64Encoder with no changes. As a final example, a SocketSource or SocketSink are going to need an IP address and port. What may (or may not) need to be changed depends on the object.

有许多来源。从源类参考


  • FileSource

  • StringSource / li>
  • RandomNumberSource

  • WindowPipeSource / li>
  • SocketSource

  • FileSource
  • StringSource
  • RandomNumberSource
  • WindowPipeSource
  • SocketSource

过滤器数量您正在使用其中两个 - AuthenticatedEncryptionFilter AuthenticatedDecryptionFilter 。从过滤器类参考 FilterWithBufferedInput类参考

There are a number of filters. You are using two of them - AuthenticatedEncryptionFilter and AuthenticatedDecryptionFilter. From Filter Class Reference and FilterWithBufferedInput Class Reference:


  • HexEncoder

  • HexEncoder

  • Base32Encoder

  • Base32Decoder

  • Base64Encoder

  • Base64Encoder

  • DefaultEncryptor

  • DefaultEncryptorWithMAC

  • DefaultDecryptor

  • DefaultDecryptorWithMAC

  • ...

  • StreamTransformationFilter

  • AuthenticatedEncryptionFilter

  • AuthenticatedDecryptionFilter

  • HexEncoder
  • HexEncoder
  • Base32Encoder
  • Base32Decoder
  • Base64Encoder
  • Base64Encoder
  • DefaultEncryptor
  • DefaultEncryptorWithMAC
  • DefaultDecryptor
  • DefaultDecryptorWithMAC
  • ...
  • StreamTransformationFilter
  • AuthenticatedEncryptionFilter
  • AuthenticatedDecryptionFilter

一些水槽。从 Sink类参考


  • ArraySink

  • BitBucket / li>
  • RandomNumberSink

  • StringSink / li>
  • FileSink

  • SocketSink / li>
  • ...

  • ArraySink
  • BitBucket
  • RandomNumberSink
  • StringSink
  • FileSink
  • SocketSink
  • ...

有一些高级主题,但我不认为它们是重要的在这一刻。例如, BufferedTransformation 的作用,如果 Attachable 返回 true 。答案是过滤器和接收器是 BufferedTransformation ,而 Attachable = true 表示其过滤器(否则为Sink)。

There are some advanced topics, but I don't think they matter at the moment. For example, the role of BufferedTransformation and what it means if Attachable returns true. The answer is both Filters and Sinks are BufferedTransformation's, and Attachable = true means its a Filter (otherwise its a Sink).


...在下面的例子中,为什么需要设置密码到某事...

... in following example, why does cipher need to be set to something...

A StringSource StringSink 不需要任何内容​​,因为它只是内存中的一个bye数组。一个 FileSource FileSink 需要一个文件名,你使用 cipher 为文件名。您有提供文件名,因为文件/流相关的对象。如果您正在使用 SocketSource SocketSink ,那么您需要提供一个IP地址和端口(更正确的是,一个 socket_t )。

A StringSource and StringSink needs nothing because its just an array of byes in memory. A FileSource and FileSink needs a filename, and you are using cipher for the filename. You have to supply a filename because the objects a file/stream related. If you were using a SocketSource or SocketSink, then you would need to supply an IP address and port (more correctly, a socket_t).

以下是 FileSource 构造函数/ref/class_file_source.htmlrel =nofollow> FileSource类参考。您正在代码中使用第三个构造函数。

Here are the FileSource constructors from FileSource Class Reference. You are using the third constructor in your code.

FileSource (BufferedTransformation *attachment=NULL)
FileSource (std::istream &in, bool pumpAll, BufferedTransformation *attachment=NULL)
FileSource (const char *filename, bool pumpAll, BufferedTransformation *attachment=NULL, bool binary=true)

以下是 FileSink 构造函数.com / docs / ref / class_file_sink.htmlrel =nofollow> FileSink类参考。您正在代码中使用第二个构造函数。

Here are the FileSink constructors from FileSink Class Reference. You are using the second constructor in your code.

FileSink (std::ostream &out)
FileSink (const char *filename, bool binary=true)

这篇关于FileSink,StringSink,Filesource,StringSource Crypto ++有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆