python调包——hashlib加密

2021-06-10 03:04

阅读:372

标签:encode   code   hello   obj   一个   形式   对象   lib   cdc   

python调包——hashlib加密

#加密 md5 sha1 sha256 sha512

import hashlib

msg ="hello world"

md5 = hashlib.md5(msg.encode(‘utf-8‘))#之所以选择用utf-8对msg进行编码,是因为考虑到了msg里面可能出现中文的形式
print(md5)
# 单纯只是一个md5类型的hash对象
r = md5.hexdigest()#十六进制消化?
print(r)
print(len(r))
#5eb63bbbe01eeed093cb22bb8f5acdc3
#32

sha1 = hashlib.sha1(msg.encode(‘utf-8‘)).hexdigest()
print(sha1)
print(len(sha1))
#2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
#40

sha256 = hashlib.sha256(msg.encode(‘utf-8‘)).hexdigest()
print(sha256)
print(len(sha256))
#b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
#64

sha512 = hashlib.sha512(msg.encode(‘utf-8‘)).hexdigest()
print(sha512)
print(len(sha512))
#309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f
#128

python调包——hashlib加密

标签:encode   code   hello   obj   一个   形式   对象   lib   cdc   

原文地址:https://www.cnblogs.com/BeautifulWater/p/14466679.html


评论


亲,登录后才可以留言!