import hashlib
import hmac

m = input('输入要加密内容:')
md = hashlib.md5()#生成md5 hash对象
md.update(m.encode('utf-8'))#进行加密更新处理
print(md.hexdigest())#16进制表示,digets()为二进制表示

with open('D:\\test.txt','rb') as f:
    data = f.read()
md5 = hashlib.md5()
md5.update(data)
print(md5.hexdigest())

with open('D:\\test.txt','rb') as f:
    while True:
        data = f.read(1024)
        if not data:
            break
        md5 = hashlib.md5()
        md5.update(data)
print(md5.hexdigest())

sha1 = hashlib.sha1()
sha1.update('Biubiubiu'.encode('utf-8'))
print(sha1.hexdigest())

#带key加密
val=b'biubiubiu'
key=b'diudiu'
h=hmac.new(key, val, digestmod='MD5')
print(h.hexdigest())

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。