栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python关于hash的使用

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python关于hash的使用

项目场景:

在某些实验中,会需要一些hash算法


如何使用sha256

虽然可以直接import hashlib全部导入,但也可以仅仅使用 sha256()这个函数
from hashlib import sha256

from hashlib import sha256

if __name__ == "__main__":
    s = sha256()  # Get the hash algorithm.
    message = "y y7"
    s.update(message.encode("utf-8"))  # Hash the data.
    b = s.hexdigest()  # Get he hash value.
    print(s.digest())
    print(b)

    
    """ 
" b'xde;xdc)x13_x88 vx10xadxb4x9ex8f#xa7hDxf6GXx14xc9x94x80 
如何获取摘要 

使用方法 hexdigest() 获取16进制的摘要,也可以使用方法digest()获取以字节为单位的摘要


注意事项:

message需要进行encode编码,否则会报错TypeError: Strings must be encoded before hashing

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/958304.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号