hashlib 模块如何对文件进行加密生成MD5码
使用sercr()函数对文件生成MD5码
import hashlib
def sercr(data_path):
with open(data_path,mode='rb') as f1:
data = hashlib.md5()
while True:
data_read = f1.read(1024)
if not data_read:
break
data.update(data_read)
return data.hexdigest()
print(sercr('PCIe_PHY_Test_Spec_2019_NCB_4.0_1.0.pdf'))
# MD5: A356068D1242616EFB94B86894804134
# SHA1: 612C4D4315B4536C1020D42928240BF4BFAA0A60