Python script for SHA checksum of large files.
1. Below is the information of the file that will be used for the SHA checksum (the CentOS ISO file is approximately 4.39 GB):
2. Make sure the file path in the Python script matches the actual location of the file.
E:\ISO\CentOS-7-x86_64-DVD-2009.iso
3. Run the script using PowerShell or CMD:
python scriptfile_name.py
4. SHA checksum result (appears after about 90 seconds):
Note: The speed of the checksum calculation depends on the device specifications; the higher the specifications, the faster the checksum process
================================================
Sample Python Script
================================================
================================================
Related article (MD5 Checksum):
My Pocket : Python Script for MD5 Checksum
================================================
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 1 15:40:00 2025
Checksum calculator using SHA-256 for large files
"""
import hashlib
def get_checksum(file_path, algorithm='sha256'):
"""
Calculate the checksum of a large file using a SHA algorithm.
The 'algorithm' parameter can be: 'sha1', 'sha224', 'sha256', 'sha384', or 'sha512'.
"""
chunk_size = 8192 # read 8KB per chunk for memory efficiency
# ensure the algorithm is valid
if algorithm not in hashlib.algorithms_available:
raise ValueError(f"Algorithm '{algorithm}' is not supported.")
h = hashlib.new(algorithm)
with open(file_path, 'rb') as f:
while chunk := f.read(chunk_size):
h.update(chunk)
return h.hexdigest()
if __name__ == "__main__":
file_path = r"E:\ISO\CentOS-7-x86_64-DVD-2009.iso"
print("SHA-256 Checksum:", get_checksum(file_path, 'sha256'))
================================================
Related article (MD5 Checksum):
My Pocket : Python Script for MD5 Checksum
Thank you.
Tidak ada komentar:
Posting Komentar