hash_utils.py 404 B

123456789101112131415
  1. import hashlib
  2. def compute_md5(file_bytes):
  3. hasher = hashlib.md5()
  4. hasher.update(file_bytes)
  5. return hasher.hexdigest().upper()
  6. def compute_sha256(input_string):
  7. hasher = hashlib.sha256()
  8. # 在Python3中,需要将字符串转化为字节对象才能被哈希函数处理
  9. input_bytes = input_string.encode('utf-8')
  10. hasher.update(input_bytes)
  11. return hasher.hexdigest()