Skip to content

How to Verify a SHA-256 Hash After Copying Digital Evidence

Verify a SHA-256 hash on Windows, macOS, or Linux with a three-file exercise. Learn what a match means and what to record when hashes differ.

By Sourabh6 min read

You copied an evidence file to another drive. The filename and size look right, but how do you know the copy contains the same bytes? Calculate the copy’s SHA-256 hash and compare all 64 characters with a reference hash you trust. For a handoff, that reference should identify the exact file the sender released.

You can try it here with three harmless text files: an original, an exact copy, and a copy with one extra line. You’ll see where to find the number, what it tells you, and how to write a short handoff note somebody else can check.

Get the Reference Hash Before You Compare Anything

A SHA-256 hash is a 64-character hexadecimal value calculated from a file’s bytes. Rename the file and its hash stays the same. Change the bytes inside it and you should expect a different value. The hash verification glossary explains where this check fits in evidence handling.

Ask the sender for the algorithm, the full digest, and the exact filename or item ID. You also need to know what they hashed. A ZIP archive, a file extracted from it, an E01 container, and the acquisition data verified inside that container are different things. Suppose you received photos.zip and the sender gave you a hash for the archive. Check photos.zip first. If you then unpack it, an individual photo will have its own hash. Both values can be useful, as long as your notes say which one belongs to which file.

Keep the reference in the case record or share it through an independently trusted channel. If the reference and the file both come from an unverified message, matching values only show that the message supplies a consistent pair. A receipt recorded before transfer gives you a baseline you can tie back to the item. A reference you calculate later can help check future copies. It cannot tell you what the bytes looked like before you received the file.

Teaching illustration. Compare the delivered file with the digest recorded for that item in the sender’s trusted handoff record.

Create Three Practice Files

On macOS or Linux, run this in an empty practice folder:

bash
printf 'ForensicSpot practice file\n' > master.txt
cp master.txt received.txt
cp master.txt changed.txt
printf 'One extra line\n' >> changed.txt

On Windows, use PowerShell in an empty practice folder. These commands explicitly write ASCII bytes with a line feed, so the sample matches the shell version byte for byte.

powershell
$bytes = [Text.Encoding]::ASCII.GetBytes("ForensicSpot practice file`n")
[IO.File]::WriteAllBytes((Join-Path (Get-Location) 'master.txt'), $bytes)
Copy-Item -LiteralPath .\master.txt -Destination .\received.txt
$extra = [Text.Encoding]::ASCII.GetBytes("One extra line`n")
[IO.File]::WriteAllBytes((Join-Path (Get-Location) 'changed.txt'), [byte[]]($bytes + $extra))

You have a 27-byte master and an identical 27-byte copy. The changed copy has 42 bytes. In real work, resist the temptation to use file size as a shortcut. Two different files can have the same length. If you only have the sender’s file size, you can use it to spot an incomplete download, then ask for the digest to make the stronger check.

Calculate and Compare the SHA-256 Values

On macOS:

bash
shasum -a 256 master.txt received.txt changed.txt

On Linux:

bash
sha256sum master.txt received.txt changed.txt

On Windows:

powershell
Get-FileHash -LiteralPath .\master.txt,.\received.txt,.\changed.txt -Algorithm SHA256 |
    Format-List Path,Hash

Here is the output recorded on macOS. PowerShell can display uppercase hexadecimal characters. Compare their values without regard to letter case, and keep all 64 characters when recording the result.

text
844ac1acd4bd608904b4b774dd321a9eabd89cabd19ae1c8315afdd25eeaebaf  master.txt
844ac1acd4bd608904b4b774dd321a9eabd89cabd19ae1c8315afdd25eeaebaf  received.txt
1b65bf32d5045c3c7f1b3c84a5088058d192fb386852864e22077ff313bd8c8d  changed.txt

The first two values match. You can record that the received file is byte-consistent with the reference. The third value differs because the copy contains another line. The hash itself gives you no location for the change or explanation of how it occurred. It also cannot tell you who created the original contents or fill in a missing handoff record.

In the exercise, the copied files are easy to tell apart once you calculate their SHA-256 values.

Try a Change That Leaves the File Size Alone

Back in the practice folder on macOS or Linux, change one letter from lowercase to uppercase:

bash
printf 'ForensicSpot practice File\n' > same-size.txt
wc -c master.txt same-size.txt

Use the SHA-256 command for your system on both files. In the macOS lab, both files were 27 bytes, yet same-size.txt began with 17f5b06678d1 and the master began with 844ac1acd4bd. Those short prefixes help you see the difference here. Use the full values in a real comparison. If you are trying the same exercise on Windows, use the same ASCII and line-feed setup as above so the capital letter is the only change.

Changing a single lowercase letter to uppercase leaves both files at 27 bytes. The full SHA-256 values differ.

Compare Against the Sender’s Recorded Value

In the exercise, you can hash the master whenever you like. In a real handoff, you often have only the delivered file and the sender’s recorded digest. In PowerShell, for example:

powershell
$reference = '844ac1acd4bd608904b4b774dd321a9eabd89cabd19ae1c8315afdd25eeaebaf'
$received = (Get-FileHash -LiteralPath .\received.txt -Algorithm SHA256).Hash
$received -ieq $reference

The practice file returns True. Substitute the full trusted reference in a real case. For an E01 acquisition, record the tool’s image verification result separately from any SHA-256 hash you calculate on the container files for transfer. The FTK Imager E01 walkthrough shows where to find the acquisition check.

What to Do When the Hashes Differ

First check the input before interpreting the mismatch. Did you hash the correct file with SHA-256? Is the reference for the ZIP or for a file inside it? Could a transfer still be in progress, or could you have opened the file in an editor that saved different line endings? Checking size and path can help you establish what you actually examined. Neither is a substitute for the digest.

Here are three ways a check can go wrong before you get to that point:

  • A 32-character reference may be MD5, and a 40-character one may be SHA-1. Ask which algorithm was used. The length can help you spot a likely mix-up, but it cannot confirm where the value came from.
  • If PowerShell cannot find the file, run Get-Location and check that you are in the practice folder. For a path with spaces, put the full path in quotes. If the tool cannot read the file, record the error and resolve access before writing down a result.
  • If you received a split image or several files, match each filename with its own reference and check that every expected part arrived. Keep one line per file in the record.

If you still have a mismatch, preserve the received file and both recorded values. Recheck against the trusted baseline, contact the sender through the agreed channel, and record any replacement as a separate copy. If you can obtain the verified source again, repeat the transfer and verify the new copy. Keep the discrepancy in the record even if the second attempt works.

Keep the received file available while you verify the reference and document the discrepancy.

A useful handoff note identifies the item, the two digests, where the reference came from, who verified the copy, and when. It also records any follow-up. If you have to ask for a fresh transfer, label the first copy and the replacement separately. Make it clear which file, if either, matched. Here is a short example for the practice files:

text
Item: FS-LAB-01, received.txt
Algorithm: SHA-256
Reference source: practice sender record for master.txt
Reference: 844ac1acd4bd608904b4b774dd321a9eabd89cabd19ae1c8315afdd25eeaebaf
Calculated: 844ac1acd4bd608904b4b774dd321a9eabd89cabd19ae1c8315afdd25eeaebaf
Result: match
Verifier and time: [name and date/time with time zone]

A hash supports the integrity check. The custody record tells you what happened to the evidence between people and systems. The digital first response lesson explains how both fit together.

Try the same check against changed.txt and write one line describing the result without guessing why it changed. That’s the sentence you want to be able to write when a real handoff looks wrong.

Was this page helpful?