0

I am using the funcitons in windows and generating a SHA-1 hash.

Here is part of the function I am using, its not the entire fucntion but this function returns a GUID.

GUID guid;

res = CryptGetHashParam(hHash, HP_HASHVAL, (BYTE*)&guid, &dwHashLen, 0);

I am pretty sure it works but I need to unit test it as its in a very sinseitive part of our code base.

What I would like to be able to do is either find a test vector of some sample strings hashed to GUID or else find a way of convering the GUID to a string.

The test data I use is taken from the site https://www.di-mgt.com.au/sha_testvectors.html

so

hashing the string "abc" using SHA-1 should yield a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d hashing the string abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq should yield 84983e44 1c3bd26e baae4aa1 f95129e5 e54670f1

zdan
  • 28,667
  • 7
  • 60
  • 71
PMcK
  • 393
  • 1
  • 2
  • 11
  • Why do you think you are getting a GUID and not binary data? – Richard Critten May 29 '18 at 16:15
  • You should post the relevant source code and output too – Asesh May 29 '18 at 16:17
  • SHA-1 is not encryption, it's hashing. Also, are you using the [deprecated `CryptCreateHash`](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379908(v=vs.85).aspx) or the [CNG functions](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376210(v=vs.85).aspx)? Show some code. – Thomas May 29 '18 at 16:18

2 Answers2

0

Why not use a standard GUID generation function using the timestamp as the input. In fact timestamp is the best GUID.

  • What I am looking for is some test data to prove that my code working correctly. I know that a SHA-1 of abc is "a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d", but the functions that I am using in WinCrypt.h return a GUID, so how do I know that the GUID is correct. – PMcK May 30 '18 at 07:53
0

Turns out you cannot have a SHA-1 digest represented as a GUID as SHA-1 digests are a differnt size from GUID. Stupid mistake on my part.

PMcK
  • 393
  • 1
  • 2
  • 11