mirror of
https://github.com/opendatalab/MinerU.git
synced 2026-09-21 12:42:22 +08:00
16 lines
404 B
Python
16 lines
404 B
Python
import hashlib
|
|
|
|
|
|
def compute_md5(file_bytes):
|
|
hasher = hashlib.md5()
|
|
hasher.update(file_bytes)
|
|
return hasher.hexdigest().upper()
|
|
|
|
|
|
def compute_sha256(input_string):
|
|
hasher = hashlib.sha256()
|
|
# 在Python3中,需要将字符串转化为字节对象才能被哈希函数处理
|
|
input_bytes = input_string.encode('utf-8')
|
|
hasher.update(input_bytes)
|
|
return hasher.hexdigest()
|