本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名原文链接~~~

Python基础(23)之hashlib模块

微信搜索 zze_coding 或扫描 👉 二维码关注我的微信公众号获取更多资源推送:


md5 和 sha 加密

import hashlib

str = '123'
md5_helper = hashlib.md5()
md5_helper.update(bytes(str, 'utf-8'))
print(md5_helper.hexdigest())  # 202cb962ac59075b964b07152d234b70

sha_helper = hashlib.sha1()
sha_helper.update(bytes(str, 'utf-8'))
print(sha_helper.hexdigest())  # 40bd001563085fc35165329ea1ff5c5ecbdbbeef

加盐

import hashlib

str = '123'
md5_helper = hashlib.md5()
md5_helper.update(bytes(str, 'utf-8'))
print(md5_helper.hexdigest())  # 202cb962ac59075b964b07152d234b70
# 加盐
md5_salt_helper = hashlib.md5("salt".encode("utf8"))
md5_salt_helper.update(bytes(str, 'utf-8'))
print(md5_salt_helper.hexdigest())  # 8c4fb7bf681156b52fea93442c7dffc9

如果这篇文章对您有帮助,可点击下方链接分享给你的朋友们😋,如果遇到问题欢迎评论、留言~~~😇

评论

公众号:zze_coding

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×