FileSink、StringSink、FileSourcem StringSource 到底有什么区别。
Sources、Filters 和 Sinks 是 Crypto++ 中 Pipeline 设计的一部分。数据从源流出,经过过滤器转换,然后到达接收器。
所有来源均可互换。所有过滤器均可互换。所有水槽均可互换。例如,要在StringSink
and FileSink
,您需要提供一个带有FileSink
。否则,它们的操作相同。作为另一个例子,您可以在HexEncoder
and Base64Encoder
没有任何变化。作为最后一个例子,SocketSource
or SocketSink
将需要 IP 地址和端口。哪些内容可能(或可能不需要)需要更改取决于对象。
有很多来源。从源类参考 http://www.cryptopp.com/docs/ref/class_source.html:
FileSource
StringSource
RandomNumberSource
WindowPipeSource
SocketSource
有许多过滤器。您正在使用其中两个 -AuthenticatedEncryptionFilter
and AuthenticatedDecryptionFilter
. From 过滤器类参考 http://www.cryptopp.com/docs/ref/class_filter.html and FilterWithBufferedInput 类参考 http://www.cryptopp.com/docs/ref/class_filter_with_buffered_input.html:
HexEncoder
HexEncoder
Base32Encoder
Base32Decoder
Base64Encoder
Base64Encoder
DefaultEncryptor
DefaultEncryptorWithMAC
DefaultDecryptor
DefaultDecryptorWithMAC
- ...
StreamTransformationFilter
AuthenticatedEncryptionFilter
AuthenticatedDecryptionFilter
有多个水槽。从接收器类参考 http://www.cryptopp.com/docs/ref/class_sink.html:
ArraySink
BitBucket
RandomNumberSink
StringSink
FileSink
SocketSink
- ...
有一些高级主题,但我认为目前它们并不重要。例如,角色BufferedTransformation
以及如果Attachable
回报true
。答案是 Filter 和 Sinks 都是BufferedTransformation
's, and Attachable = true
意味着它是一个过滤器(否则它是一个接收器)。
...在下面的示例中,为什么需要将 cipher 设置为某些内容...
A StringSource
and StringSink
不需要任何东西,因为它只是内存中的一组再见。 AFileSource
and FileSink
需要一个文件名,并且您正在使用cipher
为文件名。你have提供文件名,因为对象与文件/流相关。如果您使用的是SocketSource
or SocketSink
,那么您需要提供 IP 地址和端口(更正确地说,是socket_t
).
这里有FileSource
构造函数来自文件源类参考 http://www.cryptopp.com/docs/ref/class_file_source.html。您在代码中使用第三个构造函数。
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
构造函数来自FileSink 类参考 http://www.cryptopp.com/docs/ref/class_file_sink.html。您在代码中使用第二个构造函数。
FileSink (std::ostream &out)
FileSink (const char *filename, bool binary=true)