python模塊學習之hashlib模塊學習
阿新 • • 發佈:2018-06-23
utf nco sha256 pan 生成 BE ace unicode hello
1 # 加密模塊 2 import hashlib 3 4 # md5 加密 md5 5 # 1.初始化md5模塊 生成md5對象 6 # 2.引入要加密的數據 update 7 # 3.獲取加密值 hexdigest 8 m = hashlib.md5() 9 m.update(‘hello world‘.encode(‘utf8‘)) #python3 中默認的字符編碼是unicode 10 print(m.hexdigest()) #5eb63bbbe01eeed093cb22bb8f5acdc3 11 12 # sha 加密 sha256 調用方式最多13 # 1.初始化sha256對象 14 # 2.引入要加密的數據 15 # 3.獲取加密值 16 m1 = hashlib.sha256() 17 m1.update("hello world".encode("utf8")) 18 print(m1.hexdigest()) #b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
python模塊學習之hashlib模塊學習