mfsig.com
sha-256content-hashintegrityprovenance5 min read

Content hashing with SHA-256 for scientific result files

A SHA-256 content hash proves a result file is byte-for-byte the one that was computed. What it covers, what it cannot, and how to check one in Python.

Updated November 28, 2026

A content hash is a fixed-length fingerprint of a file's scientific content, and SHA-256 is the function most result files use to compute it. Store the digest when the result is produced, recompute it whenever the file is read, and any change to the numbers, the method block or the identity shows up as a mismatch. The hash proves integrity. It does not prove correctness, authorship or fitness for purpose, and the distinction matters when a computed property enters a report or a filing.

What a SHA-256 digest is and why it beats a filename

SHA-256 belongs to the SHA-2 family of hash functions published by NIST. It maps an input of any length to a 256-bit digest, written as 64 hexadecimal characters. Three properties make it useful for scientific files. The same input always gives the same digest. Changing one bit of the input changes roughly half the bits of the digest, so there is no such thing as a small difference. And nobody knows how to construct a second input that gives a chosen digest, so a matching digest is strong evidence that the content is unchanged.

A filename, a modification date or a molecule name can each point to several different contents. The digest identifies the content itself, independent of where it is stored or what it is called.

What the hash proves and what it cannot

A content hash answers exactly one question, whether the content in front of you is the content that was hashed. It catches a file truncated in transfer, a spreadsheet that silently rounded the σ values on import, an edited method block, and a result quietly swapped for another molecule's. In a regulated setting it is the piece of evidence that lets a reviewer trust a copy as much as the original, which is the heart of what an audit trail for computed properties needs.

The hash cannot answer three other questions, and readers often assume it does. It does not say the method was appropriate. A sigma profile computed with the wrong protonation state hashes perfectly. It does not say who produced the file. Authorship is what a digital signature adds, by binding the digest to a private key held by a person or an organisation. A .mfsig file carries a provenance record and a content SHA-256, and should be described in those words, not as signed. And it does not say the file is suitable for the next step. In particular, a hash on a file of raw per-segment screening charges says nothing about whether those charges have been averaged. Raw σ must not be fed to a COSMO-RS or COSMO-SAC parameterisation as if it were the averaged profile those methods expect.

Hashing a file that contains its own hash

A file cannot hash all of itself, because the digest would have to be known before it is written. Every self-describing format therefore defines which part of the content the hash covers, and the hash field sits outside that part. Two designs are common. Hash the serialised content with the hash field removed or set to an empty string. Or hash a canonical serialisation of the scientific payload, with keys sorted and whitespace fixed, so that reformatting the file does not change the digest.

The second design is the better one for scientific data. A JSON file that is pretty-printed by one tool and compacted by another holds the same numbers but different bytes. A hash over raw bytes would flag a false mismatch. A hash over a canonical form does not. Whichever design a format uses, the format documentation must say so, or nobody can recompute the digest. For a .mfsig file, the anatomy page documents the fields. Confirm exactly which content the SHA-256 covers before you recompute it, rather than guess.

Checking a hash in Python, three lines and one trap

Here is the general pattern for a whole file. The pattern for a canonical payload is the same, applied to the bytes the format specifies.

import hashlib
from pathlib import Path

def sha256_of(path):
    return hashlib.sha256(Path(path).read_bytes()).hexdigest()

recorded_digest = "..."  # the value stored in the file or in your ELN
digest = sha256_of("ethanol.mfsig")
print(digest == recorded_digest)

The trap is text mode. Opening a file in text mode and reading it as a string lets the platform translate line endings and encodings, and the digest of the text then differs from the digest of the stored bytes. Always read bytes. The second trap is the one above, pretty-printing. If a colleague opened the file in an editor that reformatted it on save, a raw-byte digest will change while the content did not. A canonical-payload digest will not change.

Where the digest goes once you have it

A digest inside the file protects against corruption. A digest stored outside the file protects against substitution. Write the 64 characters into the record that uses the result. An ELN entry, a LIMS sample record, the supplementary information of a paper, the data section of a regulatory filing. Then the result and the record point to each other. Citing a computed σ-profile shows a citation format that includes the digest, and bringing σ-profiles into a LIMS or ELN covers where to store it in a laboratory system.

Consider a worked example. A process chemist orders the σ-profile of ethanol, SMILES CCO, through the try page and receives a .mfsig file. She computes the SHA-256 on her workstation and compares it with the value in the file. They match. She pastes the digest into the ELN entry for the solvent screen. Two years later a reviewer asks for the input behind one solvent ranking. She retrieves the file, recomputes the digest, and shows it matches the ELN. The reviewer now knows which σ-profile is under discussion, before anyone argues about the method.

Key points

  • SHA-256 gives a 64-character digest that changes completely when any bit of the content changes.
  • A content hash proves integrity, not correctness, not authorship and not fitness for the next calculation.
  • A file cannot hash all of itself, so the format must say which content the digest covers and whether it is canonicalised.
  • Read bytes, not text, when recomputing a digest, and know whether reformatting is allowed to change it.
  • Store the digest outside the file too, in the ELN, LIMS or filing that relies on the result.

Questions people ask

What is a SHA-256 content hash?
SHA-256 is a cryptographic hash function that turns any input into a fixed 256-bit digest, usually written as 64 hexadecimal characters. The same bytes always give the same digest, and changing a single bit changes about half the digest. A content hash is that digest computed over the scientific content of a file so it can be checked later.
Does a content hash prove a result is correct?
No. A hash proves only that the bytes you hold are the bytes that were hashed. A wrong result hashes just as well as a right one. Correctness comes from the method, its validation and the convergence record. The hash guarantees that none of those were altered after the fact.
Is a content hash the same as a digital signature?
No. A hash proves integrity, meaning the content has not changed. A digital signature adds authorship by binding a hash to a private key. A .mfsig file carries a provenance record and a content SHA-256, not a signature, and the two should not be confused when writing a filing.
How do I check the SHA-256 of a file on my own machine?
In Python, open the file in binary mode, read the bytes and pass them to hashlib.sha256, then compare the hexdigest with the recorded value. For a file that embeds its own hash, hash the part of the content that the file format says is covered, which the format documentation specifies.

Further reading

In practice: Each .mfsig file records the method, the package versions read at run time, the geometry convergence flag and a content SHA-256, and no file is written when the SCF does not converge. The lineage and audit pages describe the record in full.

Generate a σ-profile from your SMILES

Free converter for a profile you already have, a reference-grade DFT run with its provenance record when it has to be defensible.