python學習筆記5 加密模組hashlib

2022-07-28 03:36:08 字數 993 閱讀 6026

import

hashlib

#md5

ybm_pwd='

yuanbapqingsdfs234ff234hf@f'#

m = hashlib.md5() #

bytes_ybq = ybm_pwd.encode()#

把字串轉成bytes型別

m.update(bytes_ybq) #

加密,不能字串,只能傳bytes型別,二進位制

#print(m.hexdigest()) #加密後的結果

def md5_password(st:str):#

限定了入參的型別,只能為string型別

bytes_st = st.encode() #

轉成二進位制型別

m = hashlib.md5(bytes_st) #

加密return m.hexdigest() #

返回加密後的結果

sha_256 =hashlib.sha256(bytes_ybq)

sha512 =hashlib.sha512(bytes_ybq)

print

(sha512.hexdigest())

#print(dir(m))

#md5加密是不可逆的,不能被解密的。

md5 md5af

123456f0dfb4c958c67903e542e31c729c629b

撞庫import

base64

s='hahaha

'byte_s = s.encode() #

字串變成二進位制

res = base64.b64encode(byte_s) #

base64編碼

print(res.decode()) #

把bytes轉成字串。

jie_mi_res = base64.b64decode(res.decode()) #

base64編碼

python學習筆記(5) 模組

python 模組 module 是乙個 python 檔案,以 py 結尾,包含了 python 物件定義和python語句。模組讓你能夠有邏輯地組織你的 python 段。把相關的 分配到乙個模組裡能讓你的 更好用,更易懂。模組能定義函式,類和變數,模組裡也能包含可執行的 下例是個簡單的模組 s...

python學習筆記(十一) md5加密

md5加密 import hashlib 加密,md5加密不可逆 1 字串轉成bytes 2 用hashlib.md5進行加密 3 獲取加密結果 s 123456 s s.encode 字串轉bytes m hashlib.md5 s md5加密 m hashlib.sha256 s 加密resul...

Python 加密模組

這裡介紹hashlib模組。2 加密 hashlib模組有很多種加密方法,如hashlib.sha224 hashlib.blake2b 等,這裡以md5加密為例。加密時,不能直接對字串進行加密,需要先將字串轉化為bytes型別,用str.encode 下面是乙個完整的加密過程。將上述功能寫成下列函...