|
QuickHash Library |
C++ Interface |
|
CHMAC::Final
void Final( unsigned char* pDest );
Parameters
pDest
[out] Pointer to the memory
buffer that will receive the HMAC.
Remarks
Call this member function to retrieve the HMAC from the
CHMAC
object. The HMAC is retrieved in the memory buffer
pointed by pDest. The size of the memory buffer pointed by pDest
must be at least CHMAC<T>::DIGESTSIZE bytes.
For example, the size of the memory buffer pointed by pDest
must be at least CHMAC<CMD5>::DIGESTSIZE bytes, if the HMAC is
calculated using the MD5 hash algorithm.
After the Final method is performed, the
CHMAC
object is initialized for new calculations, as it would be constructed
again. To initialize the CHMAC object with another key, call the Init
method.
Example
#include <fstream>
#include <QuickHash.h>
using namespace std;
using namespace QuickHash;
const unsigned int BUFF_SIZE = 1024;
int main()
{
fstream file( "c:\\test.txt", ios::in | ios::binary );
if( !file )
return 1;
unsigned char buff[ BUFF_SIZE ];
unsigned char hmac[ CHMAC<CSHA1>::DIGESTSIZE ];
char key[] = "My Password";
//Instantiate a CHMAC object that uses SHA1 hash algorithm
CHMAC<CSHA1> hm( (const unsigned char*)key, strlen( key ) );
//Calculate the HMAC incrementally block by block using Update
while( !file.eof() )
{
file.read( ( char* )buff, BUFF_SIZE );
hm.Update( buff, file.gcount() );
}
//Do final changes and get the HMAC
hm.Final( hmac );
//Use the HMAC
//...
file.close();
return 0;
}
|
|
CHMAC Overview
| Class Members
|
Useful Links | HashCalc
See Also
CHMAC::FinalHex, CHMAC::Update, CHMAC::Init
|