0%

python计算MD5值

计算字符串的MD5值

1
2
3
4
5
import hashlib

string = ''
md5 = hashlib.md5(string.encode('utf-8')).hexdigest()
print(md5)

计算文件的MD5值

1
2
3
4
5
6
7
import hashlib

file = ''
md5file = open(file, 'rb')
md5 = hashlib.md5(md5file.read()).hexdigest()
md5file.close()
print(md5)