-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.py
More file actions
28 lines (23 loc) · 717 Bytes
/
hash.py
File metadata and controls
28 lines (23 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import hashlib
def md5_text(t:str):
h = hashlib.md5()
h.update(t.encode("utf-8"))
return h.hexdigest()
def sha256_text(t:str):
h = hashlib.sha256()
h.update(t.encode("utf-8"))
return h.hexdigest()
def md5_file(path):
with open(path, 'rb') as file:
t = file.read()
h = hashlib.md5()
h.update(t.encode("utf-8"))
return h.hexdigest()
def sha256_file(path):
with open(path, 'rb') as file:
t = file.read()
h = hashlib.sha256()
h.update(t.encode("utf-8"))
return h.hexdigest()
def check_file(file_path,hash_md5,hash_sha256):
return md5_file(path=file_path) == hash_md5 and sha256_file(path=file_path) == hash_sha256