给定文件名,如何使用 Crypto++ 获取 Adler32
给定“字符串文件名”,如何使用 C++ Crypto++ 库获取 Adler32 校验和。 我对使用他们的 Source 和 Sink 系统有点困惑。
下面我有执行 MD5 的代码框架,但我似乎找不到任何有关 Adler32 用法的示例或教程。
string filename = "/tmp/data.txt"
string file_adler32_digest;
string file_md5_digest;
MD5 hashMD5;
FileSource fs( filename.c_str(),
true,
new HashFilter( hashMD5,
new HexEncoder( new StringSink( file_md5_digest ) ) ) );
/* Confusion begins here */
//how do I do the adler32 ?
/* Confusion ends here */
cout << file_adler32_digest << endl
<< file_md5_digest << endl;
这里有很好的示例和示例代码 http://www.cryptopp.com/wiki/Category:Sample< /a> 用于所有 Crypto++(除了我想要的 Adler32 东西)
Given a "string filename", how can I get the Adler32 checksum using the C++ Crypto++ library. I am a little confused about using their Source and Sink system.
Below I have the skeleton of the code that does MD5, but I can't seem to find any examples or tutorials on the Adler32 usage.
string filename = "/tmp/data.txt"
string file_adler32_digest;
string file_md5_digest;
MD5 hashMD5;
FileSource fs( filename.c_str(),
true,
new HashFilter( hashMD5,
new HexEncoder( new StringSink( file_md5_digest ) ) ) );
/* Confusion begins here */
//how do I do the adler32 ?
/* Confusion ends here */
cout << file_adler32_digest << endl
<< file_md5_digest << endl;
Good samples and sample code here http://www.cryptopp.com/wiki/Category:Sample for all the Crypto++ (except for the Adler32 stuff I want)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您遵循此 http://www.cryptopp.com/wiki/HashFilter,您将获得将 hashMD5 更改为 hashAdler32,将 file_md5_digest 更改为 file_adler32_digest
此后
file_adler32_digest
应包含所需的哈希值。If you follow this http://www.cryptopp.com/wiki/HashFilter, you have to change hashMD5 for hashAdler32, and file_md5_digest for file_adler32_digest
After this
file_adler32_digest
should contain the desired hash.好的。 该特殊设计的灵感来自 Unix 管道系统。 如果您了解 Unix 管道以及 doata 如何流过它,那么您就了解 Crypto++ Pipeline。
例如,以下 Unix 命令:
将成为以下 Crypto++ 程序:
正如 Ismael 向您展示的那样,它很简单:
但这里有一个见解:在 Crypto++ 中,数据从 源 到 接收器。 在这之间,它将遇到转换数据的过滤器。
上面,您有两个过滤器: HashFilter 和 HexEncoder。 所有过滤器都继承自
BufferedTransformation
,因此它们都可以链接起来以一致的方式在一起。Adler32
本身不是过滤器。 但它继承自HashTransformation
,这就是HashFilter 使用。 因此,您可以交换任何基于 HashFilter 的对象,一切都会正常工作。您可以在 HashFilter 找到基于对象的列表。 cryptopp.com/docs/ref/class_hash_transformation.html" rel="nofollow">HashTransformation 类参考。 它们包括所有哈希值(如 MD5、SHA 和 Whirlpool)、Adler32 和 CRC32。
OK. That particular design is inspired by the Unix pipe system. If you understand Unix pipes and how doata flows through it, then you understand the Crypto++ Pipeline.
For example, the following Unix commands:
would become the following Crypto++ program:
As Ismael showed you, its as simple as:
But here's the insight: In Crypto++, data flows from Sources to Sinks. In between, it will encounter Filters that transform the data.
Above, you have two filters: the HashFilter and the HexEncoder. All the filters inherit from a
BufferedTransformation
, so they can all be chained together in a consistent manner.Adler32
itself is not a filter. But it inherits fromHashTransformation
, and that is what HashFilter uses. So you can swap in any HashFilter based object and things will just work.You can find a list of HashFilter based object at HashTransformation Class Reference. They include all the hashes (like MD5, SHA and Whirlpool), Adler32 and CRC32.