Do you know what is meant by HASH?

A fixed-size result obtained by applying a mathematical function (the hashing algorithm) to an arbitrary amount of data. (from MSDN)

We can create hashes by using Microsoft Crypto APIs.

I’m now explaining the procedures for making hash of a data using MS Crypto APIs.

  • Acquire access to key container

Use the API CryptAcquireContext()

  • Create an empty hash object

Use the API CryptCreateHash()

  • Hold the Data to in a byte array
  • Add the Data buffer to the Hash

Use the API CryptHashData()

  • Read the length of the Hashed Data

Use the API CryptGetHashParam()

  • For example

      DWORD dwCount = sizeof(DWORD);
      DWORD dwHashLen;
      if(!CryptGetHashParam(m_hHash, HP_HASHSIZE, (BYTE *)&dwHashLen, &dwCount, 0))
            TRACE(_T(“Error during CryptGetHashParam.\n”));
            return false;

Now the dwHashLen variable holding the Length

  • Get the Hashed data

BYTE *pbHash = new BYTE[dwHashLen];
if(!CryptGetHashParam(m_hHash, HP_HASHVAL, pbHash, &dwHashLen, 0))
            TRACE(_T(“Error during CryptGetHashParam.\n”));
            return false;

           After that , pbHash hold the hashed data. 🙂

Now this seems so simple right…?

Start programming using MS Crypto APIs.. 🙂