Skip to content

outisdz/Python-Integrity-Check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Python Integrity Check

Python Rich Output

🔍 Overview

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.


✨ Features

  • 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

🛠️ Installation

  1. Clone the repository:

    git clone https://github.com/outisdz/Python-Integrity-Check.git
    cd Python-Integrity-Check
  2. Install dependencies:

    pip install rich

🚀 Usage

Run the script directly with Python:

python integrity-check.py [OPTIONS]

Options & Arguments

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.


Examples

1. Create a Hash File

python integrity-check.py -s mydoc.pdf -c

This will create a hash file (mydoc.pdf_hash256) in the current directory.

2. Create a Hash File to a Custom Location

python integrity-check.py -s myphoto.jpg -d ./hashes/ -c

If ./hashes/ is a directory, you will be prompted for a file name.

3. Check File Integrity Using a Hash File

python integrity-check.py -s mydoc.pdf -d mydoc.pdf_hash256 --check

4. Check Integrity with a Provided Digest

python integrity-check.py -s mydoc.pdf --dhash 3f4e2a...  # (Your hash here)

🧩 How Does It Work?

  • 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.

⚠️ Notes & Security

  • 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.

📑 License

MIT License (see LICENSE if present).


🙏 Acknowledgments

  • Rich for beautiful CLI output.
  • Inspired by best practices in digital forensics.

💬 Feedback

Feel free to open issues or pull requests!

About

integrity-check.py is a lightweight Python script for verifying file integrity using SHA-256 hashes.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages