QuickHash Library C++ Interface

CHMAC::Init

void Init( const unsigned char* pKey, unsigned int nKeyLength = DEFAULTKEYLEN );

void Init( const char* pKey );

Parameters

 pKey

    [in]

    In the first case - pointer to the continuous memory block used as the key.

    In the second case - pointer to the null-terminated string used as the key.

 nKeyLength

    [in] Length in bytes of the key.  

Remarks

Initializes the CHMAC object with the key pointed by pKey.

Example

 

#include <string.h>
#include <QuickHash.h>
using namespace QuickHash;

int main()
{
    char string[] = "Test String";
    char key[] = "Password";
    char newkey[] = "New Password";

    char hmachex[ CHMAC<CRIPEMD160>::HEXDIGESTSIZE ]; //0 terminated

    //Instantiate a CHMAC object that uses RIPEMD160 hash algorithm

    CHMAC<CRIPEMD160> hm( (const unsigned char*)key, strlen( key ) );

    //Calculate the HMAC using Update and FinalHex

    hm.Update( (const unsigned char*)string, strlen( string ) );
    hm.FinalHex( hmachex ); //FinalHex reinitializes the hm object for the next use 

    //Use the HMAC
    //...

    //Initialize the hm object with the new key

    hm.Init( (const unsigned char*)newkey, strlen( newkey ) );

    //Calculate the HMAC using Update and FinalHex

    hm.Update( (const unsigned char*)string, strlen( string ) );
    hm.FinalHex( hmachex ); //FinalHex reinitializes the hm object for the next use 

    //Use the HMAC
    //...

    return 0;
}

 

 

Note.

In the above example newkey is a null-terminated string. Therefore, the call

    hm.Init( (const unsigned char*)newkey, strlen( newkey ) );

can be replaced by

    hm.Init( newkey );

 

CHMAC Overview   |   Class Members   |   Useful Links   |   HashCalc

 

See Also    CHMAC::Update, CHMAC::Final, CHMAC::FinalHex


 

 

Send Feedback to SlavaSoft Inc. Tell a friend about QuickHash Library