integrity-check.py
is a Python script for verifying file integrity.
It generates a SHA-256 hash that includes both file contents and timestamp metadata, allowing you to detect tampering of both data and file attributes.
You can create and check hash files, or verify against a provided hash digest, all from a simple command-line interface.
- Hash Creation: Generates a SHA-256 hash of a file, including:
- File contents (read in chunks)
- Creation time (
ctime
) - Last modification time (
mtime
) - Last access time (
atime
)
- Integrity Verification:
- Checks integrity using a stored hash file
- Verifies directly against a provided SHA-256 digest (hex string)
- Rich CLI Output: Colored, user-friendly output using Rich
- Interactive Prompts: Prompts to overwrite files or specify names as needed
-
Clone the repository:
git clone https://github.com/outisdz/Python-Integrity-Check.git cd Python-Integrity-Check
-
Install dependencies:
pip install rich
Run the script directly with Python:
python integrity-check.py [OPTIONS]
Option / Argument | Description |
---|---|
-d , --destination |
📁 Where to store or read the hash file (default: current directory) |
-s , --source |
📄 File to hash or check (required) |
-c , --create |
🛠️ Create a hash file for the specified source file |
--check |
🔒 Check integrity of a file using its hash file |
--dhash |
🔑 Provide the hash (hex string) for direct checking |
Note: Exactly one of
--create
,--check
, or--dhash
is required per run.
python integrity-check.py -s mydoc.pdf -c
This will create a hash file (mydoc.pdf_hash256
) in the current directory.
python integrity-check.py -s myphoto.jpg -d ./hashes/ -c
If ./hashes/
is a directory, you will be prompted for a file name.
python integrity-check.py -s mydoc.pdf -d mydoc.pdf_hash256 --check
python integrity-check.py -s mydoc.pdf --dhash 3f4e2a... # (Your hash here)
- Hashes file contents and its timestamp metadata (mtime, ctime, atime).
- Any change to file content or these timestamps will be detected.
- Uses SHA-256 with HMAC comparison for secure verification.
- All output is colorized and interactive via Rich.
- Hash files are binary. Keep them safe and do not edit.
- Any change in file content or its metadata will result in a different hash.
- Do not rely solely on access/modification times for security — this is an integrity tool, not an anti-tamper solution.
MIT License (see LICENSE if present).
- Rich for beautiful CLI output.
- Inspired by best practices in digital forensics.
Feel free to open issues or pull requests!