消息摘要算法(2)-- MD5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from hashlib import md5

def encrypt_md5(s):
# 创建md5对象
obj_md5 = md5()

# 对字符串进行编码
obj_md5.update(s.encode(encoding='utf-8'))

# 加密
return obj_md5.hexdigest()

if __name__ == '__main__':
print(encrypt_md5('admin'))
print(md5('admin'.encode(encoding='utf-8')).hexdigest())