hashResult variable is not storing the correct values
<p>I have a program that generates a hash key from a file.
For example the result of the program is <code>"hash of file c:\Users\Jax\Desktop\files\file.txt is: 4db5a10d2ea73e3f76"</code>.</p>

<p>And I have a variable that has the expected hash for this file.txt:</p>

<pre><code>char hashExpected   = "4db5a10d2ea73e3f76";
</code></pre>

<p>And in a specifc part of the code I'm verifying if the result hash of the program is equal to the hash stored in the <code>hashExpected</code> variable. I have this like below. I have the <code>hashResult</code> variable storing the result hash so then I can compare. But it's not working properly because it always shows <code>Hash is different</code> even when it's equal. It seems that the <code>hashResult</code> variable is not storing the correct values.</p>

<pre><code>        for (i = 0; i &lt; cbHash; i++)
        {
            printf("%c%c",
                   rgbDigits[rgbHash[i] &gt;&gt; 4],
                   rgbDigits[rgbHash[i] &amp; 0xf]);
            hashResult[i] = rgbDigits[rgbHash[i] &gt;&gt; 4];
            hashResult[i] += rgbDigits[rgbHash[i] &amp; 0xf];
        }
        if (verify(hashResult, hashExpected))
        {
            printf("Hash is the same\n");
        }
        else
        {
            printf("Hash is different\n");
        }
</code></pre>

<p>Full program:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;windows.h&gt;
#include &lt;Wincrypt.h&gt;
#include &lt;stdbool.h&gt;
#define BUFSIZE 1024
#define MD5LEN  16

bool verify(char array1[], char array2[])
{
    int i;
    for (i = 0; array1[i] &amp;&amp; array2[i]; ++i)
    {
        if (array1[i] != array2[i])
        {
            return false;
        }
    }
    return true;
}
DWORD main()
{
    DWORD dwStatus = 0;
    BOOL bResult = FALSE;
    HCRYPTPROV hProv = 0;
    HCRYPTHASH hHash = 0;
    HANDLE hFile = NULL;
    BYTE rgbFile[BUFSIZE];
    DWORD cbRead = 0;
    BYTE rgbHash[MD5LEN];
    DWORD cbHash = 0;
    CHAR rgbDigits[] = "0123456789abcdef";
    PCSTR filename = "c:\\Users\\Jax\\Desktop\\files\\file.txt";
    char hashActual[]   = "4db5a10d2ea73e3f76";
    char hashExpected[] = "4db5a10d2ea73e3f76";
    char hashWrong[]    = "0a0a0a0a0a0a0a";
    char hashResult[] = "";
    hFile = CreateFile(filename,
                       GENERIC_READ,
                       FILE_SHARE_READ,
                       NULL,
                       OPEN_EXISTING,
                       FILE_FLAG_SEQUENTIAL_SCAN,
                       NULL);


    if (INVALID_HANDLE_VALUE == hFile)
    {
        dwStatus = GetLastError();
        printf("Error opening file %s\nError: %d\n", filename,
               dwStatus);
        return dwStatus;
    }


    // Get handle to the crypto provider
    if (!CryptAcquireContext(&amp;hProv,
                             NULL,
                             NULL,
                             PROV_RSA_FULL,
                             CRYPT_VERIFYCONTEXT))
    {
        dwStatus = GetLastError();
        printf("CryptAcquireContext failed: %d\n", dwStatus);
        CloseHandle(hFile);
        return dwStatus;
    }


    if (!CryptCreateHash(hProv, CALG_MD5, 0, 0, &amp;hHash))
    {
        dwStatus = GetLastError();
        printf("CryptAcquireContext failed: %d\n", dwStatus);
        CloseHandle(hFile);
        CryptReleaseContext(hProv, 0);
        return dwStatus;
    }


    while (bResult = ReadFile(hFile, rgbFile, BUFSIZE,
                              &amp;cbRead, NULL))
    {
        if (0 == cbRead)
        {
            break;
        }


        if (!CryptHashData(hHash, rgbFile, cbRead, 0))
        {
            dwStatus = GetLastError();
            printf("CryptHashData failed: %d\n", dwStatus);
            CryptReleaseContext(hProv, 0);
            CryptDestroyHash(hHash);
            CloseHandle(hFile);
            return dwStatus;
        }
    }


    if (!bResult)
    {
        dwStatus = GetLastError();
        printf("ReadFile failed: %d\n", dwStatus);
        CryptReleaseContext(hProv, 0);
        CryptDestroyHash(hHash);
        CloseHandle(hFile);
        return dwStatus;
    }


    cbHash = MD5LEN;


    if (CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &amp;cbHash, 0))
    {
        DWORD i;

        printf("MD5 hash of file %s is: ", filename);
        for (i = 0; i &lt; cbHash; i++)
        {
            printf("%c%c",
                   rgbDigits[rgbHash[i] &gt;&gt; 4],
                   rgbDigits[rgbHash[i] &amp; 0xf]);
            hashResult[i] = rgbDigits[rgbHash[i] &gt;&gt; 4];
            hashResult[i] += rgbDigits[rgbHash[i] &amp; 0xf];


        }
        if (verify(hashResult, hashExpected))
        {
            printf("Hash is the same\n");
        }
        else
        {
            printf("Hash is different\n");
        }
    }
    else
    {
        dwStatus = GetLastError();
        printf("CryptGetHashParam failed: %d\n", dwStatus);
    }


    CryptDestroyHash(hHash);
    CryptReleaseContext(hProv, 0);
    CloseHandle(hFile);


    return dwStatus;
}
</code></pre>