日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python实现HMAC算法与应用

發布時間:2024/5/8 python 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python实现HMAC算法与应用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?本專欄主要用python實現密碼學中的常用經典算法,例如Vigenere、3DES、RSA、ElGamal、Diffie-Hellman、RSA簽名、ElGamal簽名、HMAC、哈希算法、列移位、AES等等。
🔥文章和代碼已歸檔至【Github倉庫:cryptography-codebase】,需要的朋友們自取。或者公眾號【AIShareLab】回復 密碼學 也可獲取。

Program : HMAC

In this program, you are required to invoke the scrypt algorithms that are implemented in hashlib build-in library. Your program does the following:

  • Read the plaintext password as a text string
  • Encode the password into byte array, with utf-8 encoding
  • Read the salt byte array as a hex string
  • Invoke the scrypt method with parameters n=4n=4n=4, r=8r=8r=8, p=16p=16p=16
  • Output the result byte array as a hex string

Example Input

Thi$ i$ my passw0rd! 477d15cb740ca1da08f6d851361b3c80

Example Output

fd5963b9e6905d36ca8d00e3a740a3ab7a40b3d60237b6f2ed3025eee770f2d71bc95ba3e98265bea4308250d02f0e10bb78e710d9f0ef7ae9a4fa52a0818d27

solution code

import hashlib import base64# define the function decode_utf8 def decode_utf8(in_bytes: bytes) -> str:return in_bytes.decode('utf-8') #Read the plaintext password as a text string password_str: str = input("input the plaintext password:") # Encode the password into byte array, with utf-8 encoding password_bytes: bytes = password_str.encode("utf-8") # Read the salt byte array as a hex string salt_str: str = input("input the salt:") salt_bytes: bytes = bytes.fromhex(salt_str) # Invoke the scrypt method with parameters n = 4 ,r = 8 ,p = 16 n: int = 4 r: int = 8 p: int = 16 result_bytes: bytes = hashlib.scrypt(password_bytes, salt=salt_bytes, n=n, r=r, p=p) # Output the result byte array as a hex string result_str: str = result_bytes.hex() print(result_str)

output

input the plaintext password:Thi$ i$ my passw0rd! input the salt:477d15cb740ca1da08f6d851361b3c80 fd5963b9e6905d36ca8d00e3a740a3ab7a40b3d60237b6f2ed3025eee770f2d71bc95ba3e98265bea4308250d02f0e10bb78e710d9f0ef7ae9a4fa52a0818d27進程已結束,退出代碼為 0

A screenshot of the console output of the program

總結

以上是生活随笔為你收集整理的python实现HMAC算法与应用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。