📄 ztest_hash.txt
字号:
How do I use a hash function?
Moderator: weidai (inherited from parent)
(excerpt from a message posted to the Crypto++ mailing list)
SHA (or any other hash module) is used like this:
#include "sha.h" // or "md5.h" for MD5, etc
.
.
.
SHA().CalculateDigest(pbOutputBuffer, pbData, nDataLen);
// pbOutputBuffer must be SHA::DIGESTSIZE bytes in length
or, if you have data that's made up of multiple pieces:
#include "sha.h"
.
.
.
SHA hash;
hash.Update(pbData1, nData1Len);
hash.Update(pbData2, nData2Len);
hash.Update(pbData3, nData3Len);
hash.Final(pbOutputBuffer);
See also the definition of HashModule::CalculateDigest() in
cryptlib.h.
2001-Jan-15 3:04pm faq-o-matic
Here is an example of hashing using filters. Note that I encode the output as hex and that is why the output buffer must be 2x the size of the MD5 digest.
==============================================
#include <cryptopp/md5.h>
#include <cryptopp/filters.h>
#include <cryptopp/files.h>
#include <cryptopp/hex.h>
#include <iostream>
using namespace CryptoPP;
using namespace std;
int main( int argc, char** argv )
{
MD5 hash;
byte buffer[2 * MD5::DIGESTSIZE]; //output size of the buffer
FileSource f(argv[1], true,
new HashFilter(hash,
new HexEncoder(new ArraySink(buffer,2 * MD5::DIGESTSIZE))));
cout << string((const char*)buffer,2 * MD5::DIGESTSIZE) << endl;
return 0;
}
2002-Mar-07 1:08am boykin
[Append to This Answer]
2002-Mar-07 1:08am
Previous: How do I use a stream cipher?
Next: How do I use a message authentication code?
This document is: http://www.eskimo.com/~weidai/cgi-bin/fom.cgi?file=50
[Search] [Appearance] [Show Expert Edit Commands]
This is a Faq-O-Matic 2.719.
This FAQ is administered by Wei Dai.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -