I'm trying to encrypt files inside selected folder with SHA256. First file is always got the true SHA256sum. But after the first file, other hashes are false. The paths true, selected files and folders are true, but sha256sums are false. Can anyone explain me why? Thanks.
window = Tk()
window.title("Crypt")
l1 = Listbox(window)
def folderScan():
counter=1
hashvalue=0
BLOCKSIZE= 65536
hasher = hashlib.sha256()
try:
folder = askdirectory(parent=window, title='Select a folder')
except:
tkMessageBox.showerror("ERROR!", "Folder selection error. Exiting..")
window.destroy()
try:
for i in os.walk(folder):
print("-------------*---------------*--------------")
print("i[0]= ",i[0]) # The current path.
print("i[1]= ",i[1]) # Folders inside our path.
print("i[2]= ",i[2]) # Files inside our path.
for j in i[2]:
fullPath = i[0]+"/"+j
try:
with open(fullPath,'rb') as tara:
buf = tara.read(BLOCKSIZE)
while len(buf) > 0:
hasher.update(buf)
buf = tara.read(BLOCKSIZE)
hashvalue = hasher.hexdigest()
l1.insert(counter,fullPath)
print("For "fullPath+" the hash is: "+hashvalue)
except:
print("Encrypt failed!")
except:
tkMessageBox.showerror("Error!", "Failed to get folder content. Exiting..")
window.destroy()