Python hashlib 模块

使用 md5 加密

import hashlib

m = hashlib.md5()
m.update('hello world'.encode('utf-8'))      # 加密的字符串需要先编码成 utf-8
print(m.hexdigest())                         # 打印计算出字符串的MD5值

运行结果:
5eb63bbbe01eeed093cb22bb8f5acdc3

使用 sha256 加密

import hashlib

m = hashlib.sha256()
# print(m)

m.update('hello world'.encode('utf-8'))
print(m.hexdigest())

运行结果:
b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
原文地址:https://www.cnblogs.com/klvchen/p/8880058.html