Page 1 of 1

bug in example sha1fingerprint()

Posted: Thu Sep 29, 2011 12:29 pm
by niijel
ver 4.60 RC1
windows 64bit (but others also?)

on help page for sha1fingerprint()

[string variable as buffer example works fine!]


Example: with memory buffer

*Buffer = AllocateMemory(500)
If *Buffer
PokeS(*Buffer, "The quick brown fox jumps over the lazy dog.")
SHA1$ = SHA1Fingerprint(*Buffer, MemorySize(*Buffer))
Debug "SHA1 Fingerprint = " + SHA1$
FreeMemory(*Buffer) ; would also be done automatically at the end of the program
EndIf

will return a incorrect sha1 digest unless input string is exactly 500 bytes in length.
this is due to it using the buffer length not the data length.

code returns sha: ab57c34511256b11e101d3b1d17abfb80de95828SHA1
correct is: 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12

see http://en.wikipedia.org/wiki/SHA-1 for the above example.

Re: bug in example sha1fingerprint()

Posted: Thu Sep 29, 2011 12:38 pm
by STARGĂ…TE
As the code is there, it works properly.

In the example is the fingerprint of the entire buffer can be calculated, not only of the string!

so, no bug!