Home > Windows API > Quick way to hash data using WinAPI

Quick way to hash data using WinAPI

Use HashData.

// Usage:

// A magical string to get hashed
TCHAR szDataToHash[] = _T( "Oobolooblahblah, abracadabra, ooboboblablah, get this string hashed" );

// Determines the size of hash value to be returned.
DWORD HashVal = 0;

// Hash now
HRESULT hRes = HashData( LPBYTE( szDataToHash ), // Data to hash, can be of any type
                         _tcslen( szDataToHash ) * sizeof( TCHAR ), // Byte count of data to hash
                         LPBYTE( &HashVal ), // Hash value
                         sizeof( HashVal )); // Length of hash val

// Must return S_OK on success
ASSERT( SUCCEEDED( hRes ));

Note that this function can in a way be used for computing CRC values, though I am not sure. Sizeof HashVal determines the length of CRC. Also can be used for computing file checksums.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: