hmac模块的作用:
用于验证信息的完整性。
1、hmac消息签名(默认使用MD5加算法)
#!/usr/bin/env python # -*- coding: utf-8 -*- import hmac #默认使用是md5算法 digest_maker = hmac.new('secret-shared-key'.encode('utf-8')) with open('content.txt', 'rb') as f: while True: block = f.read(1024) if not block: break digest_maker.update(block) digest = digest_maker.hexdigest() print(digest)