# 验证消息的HMAC码 message_to_verify = b'This is a secret message' received_hmac_code = hmac_code expected_hmac_code = hmac.new(secret_key, message_to_verify, hashlib.sha256).hexdigest()
# 如果收到的HMAC码与期望的HMAC码匹配,则消息未被篡改 if received_hmac_code == expected_hmac_code: print("The message is authentic and has not been tampered with.") else: print("The message has been tampered with or the HMAC code is incorrect.")
# 检查响应状态码,确保请求成功 if response.status_code == 200: print("Request was authenticated and processed successfully.") else: print("Failed to authenticate or process the request.")
# 验证接收的文件是否完整 expected_hmac_code = hmac.new(secret_key, received_file_data, hashlib.sha256).hexdigest() if received_hmac_code == expected_hmac_code: print("The received file is authentic and has not been tampered with.") else: print("The received file has been tampered with or the HMAC code is incorrect.")