hashlib加密模块

hashlib加密模块


常用方法

import hashlib

md5 = hashlib.md5()  # 获取md5对象 ()!!!
md5.update(password.encode('utf-8'))  # 加密 切记要指定编码 encode('utf-8')
print(md5.hexdigest())  # 用hexdigest()获取计算的md5值

常用通过时间取MD5

import time
import hashlib

m = hashlib.md5(str(time.time()).encode('utf-8')) # 取时间,把时间格式转成str,定义 编码
print(m.hexdigest()) # 用hexdigest()获取计算的md5值

其他案例

import hashlib

m = hashlib.md5()
m.update(b"Hello")
m.update(b"It's me")
print(m.digest())
m.update(b"It's been a long time since last time we ...")

print(m.digest()) #2进制格式hash
print(len(m.hexdigest())) #16进制格式hash

猜你喜欢

转载自blog.csdn.net/weixin_42329277/article/details/80484032