Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
check stored sha256 value
#!/usr/bin/env python3
# file_integrity_check.py
# check file integrity from a list
# use shasum -a 256 <filename> to generate initial checksum
import hashlib
from filechecksums import * # gets precomputed variables
import os.path
def filesha256(filename, check, block_size=2**20):
# first check if the file is there
if os.path.isfile(filename):
f = open(filename, "rb")
sha256 = hashlib.sha256()
while True:
data = f.read(block_size)
if not data:
break
sha256.update(data)
f.close()
result = sha256.hexdigest()
if check == result:
print('file integrity for', filename, 'confirmed')
else:
print(filename, 'SHA256 *** mismatch ***')
else:
print('file not found', filename)
filesha256('/Users/sable/code/test.py', test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.