当前位置:
首页 >
python3 hash算法使用
发布时间:2023/12/1
37
豆豆
生活随笔
收集整理的这篇文章主要介绍了
python3 hash算法使用
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
python3下的pycryptodome库
from Crypto.cipher import * if __name__ == '__main__':message = '123'#MD5和SHA的用法差不多print("SHA3_512: " + SHA3_512.new(message.encode('utf-8')).digest().hex())print("SHA512: " + SHA512.new(message.encode('utf-8')).digest().hex())print("MD5: " + MD5.new(message.encode('utf-8')).digest().hex())print("BLAKE2S: " + BLAKE2s.new(data = message.encode('utf-8')).digest().hex())#HMAC.new(密钥,需要处理的消息,处理的哈希方法)key = 'ABCD'print("HMAC-SHA224: " + HMAC.new(key.encode('utf-8'), message.encode('utf-8'), SHA224).digest().hex())#SHANK的使用也类似print("SHAKE128: " + SHAKE128.new(message.encode('utf-8')).read(64).hex())注意:
1、我使用的pycryptodome版本为3.9.9,之前是使用了3.4.6会有很多奇怪的问题。可以这样升级
或
pip install --upgrade pycryptodome --user2、
原本的__init__文件可能会缺少一些类,使用SHA3的时候会报错,需要修改下
3、
SHAKE的read函数中的数值表示字节数,打印的结果2个字符表示1个字节。
总结
以上是生活随笔为你收集整理的python3 hash算法使用的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Windows Hook(2)调用DLL
- 下一篇: python岗位 上海_上海黑马Pyth