pythonhash对象的属性有哪些
pythonhash对象的属性有哪些
1、说明
Python中内置了一个字符加密模块:hashlib,整合了md5和sha模块。
2、属性
可以通过下述属性查看hash对象的相关信息:
name:查看当前hash对象的加密算法
digest_size:hash密文占多少个字节
block_size:hash数据库的大小
3、实例
importhashlib
origin_str='HelloPython!'
#md5加密
h_md5=hashlib.md5()
h_md5.update(origin_str.encode('utf8'))
digest_str=h_md5.hexdigest()
print("md5加密:%s"%digest_str)
#添加自定义key加密
h_md5_key=hashlib.md5('CoderPig'.encode('utf8'))
h_md5.update(origin_str.encode('utf8'))
digest_str=h_md5.hexdigest()
print("带keymd5加密后:%s"%digest_str)
#sha1加密
h_sha1=hashlib.sha1()
h_sha1.update(origin_str.encode('utf8'))
digest_str=h_sha1.hexdigest()
print("sha1加密后:%s"%digest_str)
以上就是Pythonhash对象的属性,希望能对大家有所帮助,更多Python学习教程请关注IT培训机构:千锋教育。

相关推荐HOT
更多>>
pythonfor循环是什么
pythonfor循环是什么在做遍历的时候,对于一些数据的反复循环执行,我们会用到for循环的语句。可以说这是新手入门必学的语句之一,在很多基础循...详情>>
2023-11-13 07:46:36
pythoncontextmanager()的转换
python中contextmanager()的转换1、说明当发出请求时,requests库会在将请求实际发送到目标服务器之前准备该请求。请求准备包括像验证头信息和...详情>>
2023-11-13 06:34:35
python使用items()遍历键值对
python使用items()遍历键值对字典可以用来存储各种方式的信息,所以有很多方式可以通过字典的所有键值对、键或值。说明1、即使通过字典,键值对...详情>>
2023-11-13 04:24:15
python实例方法中self的作用
python实例方法中self的作用说明1、无论是创建类的构造方法还是实例方法,最少要包含一个参数self。2、通过实例的self参数与对象进行绑定,程序...详情>>
2023-11-13 03:46:48