Jump to content

Can _Crypt_HashData() be used on binary data?


Mbee
 Share

Recommended Posts

I have scripts that use _Crypt_HashFile() to generate a hash of an entire file, binary or otherwise. But some of these scripts are hashing huge video files, which take a fairly long time, so I'm looking at finding faster alternatives. One obvious alternative would be to only hash a portion of the file in question, and only calculate the hash value of the entire file when collisions occur.

_Crypt_HashData() seems to offer a way to do this. I would read in some portion of the file and then call it and save the hash of the partial file in the hash table. Unfortunately, the function does not include a length or size parameter; all the examples of using that function only pass a text string, for which AutoIt always knows the length. But what if I try to use it on binary data?  For example, I could have my script initially hash only the first, say, 20 KB of the file. But what happens when the file is only 10 KB long?  How would I tell the _Crypt_HashData() function how many bytes to hash?

I'm asking here instead of playing with trial and error, since using hashing functions is not trivial.  Can anyone help, please?  Thanks!

ETA: When I look at the relevant article on MSDN, the call does include a length parameter.

Edited by Mbee
ETA Windows function info
Link to comment
Share on other sites

1 minute ago, RTFC said:

A faster alternative is this:

Okay, I wasn't familiar with that UDF, so please accept my tremendous thanks! :drool:

But it'll take me a while to see if I'm smart enough to modify trancexx's code to enable hashing of partial files...

 

 

Link to comment
Share on other sites

See posts #7 and #14 in that thread for exactly that.^_^

Edited by RTFC
Link to comment
Share on other sites

6 minutes ago, RTFC said:

See posts #7 and #14 in that thread for exactly that.^_^

Wow, are you amazingly helpful!  Thanks!

A question, though: In Post 14, he-she (trancexx doesn't like anyone prejudging gender by using specific pronouns) provides the code for a function named _MD5ForFirstFileChunk(). Where the hell does that come from?  From Ward?  Should I just use the code on that page, or is there some other UDF I should be using in addition to trancexx's UDF?

Link to comment
Share on other sites

15 hours ago, RTFC said:

UDF MD5ForFirstFileChunk  is in post #41 of that thread.

Thank you most kindly once again!  I truly appreciate your assistance!  I genuinely hope I haven't annoyed you, what with my failing to RTFT...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...