|
QuickHash Library |
C++ Interface |
|
CHMAC::FinalHex
void FinalHex( char* pDest, bool
bUpper = false );
Parameters
pDest
[out] Pointer to the text
buffer that will receive the HMAC.
bUpper
[in] Uppercase flag. If
bUpper is false, the received HMAC represents a lowercase string,
otherwise it represents an uppercase string.
Remarks
Call this member function to retrieve the HMAC from the
CHMAC
object. The HMAC is retrieved as a null-terminated hexadecimal string in the
text buffer
pointed by pDest. The size of the text buffer pointed by pDest
must be at least CHMAC<T>::HEXDIGESTSIZE characters.
For example, the size of the text buffer pointed by pDest
must be at least CHMAC<CMD5>::HEXDIGESTSIZE characters, if the HMAC is
calculated using the MD5 hash algorithm.
After the FinalHex 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 ];
char hmachex[ CHMAC<CPanama>::HEXDIGESTSIZE ]; //0 terminated
char key[] = "My Password";
//Instantiate a CHMAC object that uses PANAMA hash algorithm
CHMAC<CPanama> 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 in hex format
hm.FinalHex( hmachex );
//Use the HMAC
//...
file.close();
return 0;
}
|
|
CHMAC Overview
| Class Members
|
Useful Links | HashCalc
See Also CHMAC::Final, CHMAC::Update, CHMAC::Init
|