python3 hash算法使用
生活随笔
收集整理的這篇文章主要介紹了
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
- 下一篇: 我和我的四个男人剧情介绍