How to generate the hash key of given data?

27 06 2008

Hashes are everywhere. Hash is small key generated from a bulk chunk of data. The hashes are useful in many ways. They are used for table lookups and data comparison. Yes! As you think now, hash table is one among them which utilizes hashes for high speed lookups. Well, thats a good, But how to generate the hash of a chunk of data?

You can use the function – HashData(). See the following code snippet.

#include "Shlwapi.h"
// Buffer for hash Key.
const int MAX_HASH_LEN = 256;
BYTE Hash[MAX_HASH_LEN] = {0};

// Chunk of Data.
char* pData = "Hello World";

// Generate Hash Key.
HashData( (LPBYTE) pData,
          strlen( pData),
          MAX_HASH_LEN );

Do you know that in real world, Hash means – “Chop and Mix”. Have a look at Wiki –

BTW, Don’t forget to add Shlwapi.lib to project settings. 🙂

Targeted Audience – Beginners.