Created
May 15, 2019 23:22
-
-
Save sc137/19276227560e2788f1591322805a27c8 to your computer and use it in GitHub Desktop.
check stored sha256 value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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