Click here to Skip to main content
14,300,942 members
Rate this:
Please Sign up or sign in to vote.
See more:
Looking for some code which can hash an entire physical hard disk for a project

Need to Hash Disk Drive/Solid State Drives while Cloning & Imaging

What I have tried:

Have tried searching over how to implement hashing for physical drive but didn't find anything concrete.
Updated 1-Apr-19 1:51am
Nirav Prabtani 1-Apr-19 7:01am
Why do you need to do hashing of entire hard disk ??
Member 14207297 1-Apr-19 7:06am
To determine that the disk data copied from the source disk0 to destination disk1 100% replicated including free areas
#realJSOP 1-Apr-19 7:18am
How do you expect to hash free space on a drive?
Member 14207297 1-Apr-19 7:41am
We need to consider Physical Drive instead of Logical drive. In this case we read the entire drive in raw format. This can be viewed through hex viewer sector by sector. So now hash values need to be generated by considering a drive data bit-by-bit or else sector by sector. This will help to generate hash of entire physical drive.
Richard MacCutchan 1-Apr-19 7:40am
You need to access the raw sectors to read the entire drive. Google for samples and explanations.
Member 14207297 1-Apr-19 7:43am
Can you share a few samples specifically in C++ language.
#realJSOP 1-Apr-19 7:50am
He said google for the info. It's probably extensive and is not suitable for posting here.
Member 14207297 1-Apr-19 8:10am
I am able to access hard drives through createfile() and even read the whole hard disk .
Now I need assistance to generate hash value (MD5 or SHA1) post cloning data on another drive or creating image file
Richard MacCutchan 1-Apr-19 8:42am
Google will find you plenty of samples of MD5 hashing.
Member 14207297 1-Apr-19 9:09am
I am aware of MD5 hashing with file/text but need assistance with entire disk hashing .
For example, header file with function and what parameter's to pass.
Richard MacCutchan 1-Apr-19 9:42am
The form of the source data is irrelevant. A hash algorithm just reads streams of bytes and creates a value from them. Whether it comes from a file, a raw disk, an internet connection, makes no difference.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Hashing works on a byte stream, or similar - it doesn't care where you get it's data from. So as long as you can read your free space you can include it in the hash value. I wouldn't though, for the same reasons that most backup systems don't - it's technically irrelevant data which takes up valuable backup space, was well as being a potential security risk.

Whatever bytes you provide to the hashing algorithm will be used to generate the hash code, so you can use any hashing algorithm you feel appropriate. I'd suggest MD5 for this, despite it being "broken" since there is no attempt to reverse the code and this isn't a security application - it's a lot faster than SHA-512 or similar and will provide a similar level of "confirmation".

A quick google will find you loads of info on MD5 and SHA hashes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100