I’m using OpenSSL in Visual Studio for different uses of OpenSSL.
I just read a binary file to a buffer and applied SHA1 to it
EVP_DigestUpdate( hCtx, fin_buf, fin_size );
int rez=EVP_DigestFinal( hCtx, pTmpBuffer, &nDigestSz );
pDigest = new unsigned char[ nDigestSz ];
memcpy( pDigest, pTmpBuffer, nDigestSz * sizeof( unsigned char ) );
fin_buf holds bytes of the file.
FILE *fhash = fopen("hash.sha1", "wb");
fwrite(pDigest, 1, nDigestSz, fhash);
fclose(fhash);
Here i write the buffer to a .sha1 file.
I need to check the hash of the file.
Could anyone show me an example of checking the hash in OpenSSL C++?
The main idea of a hash is that when you calculate it over the same input, you will get the same hash value. If you read the original file and execute your first code part, the value of the digest should be equal to the contents of the .sha1 file.