Skip to main content
← CoursesFastAPI ProductionModule 4 · Async, Background Tasks, WebSocketsHMAC webhook signature verificationpredict50 / 101
💬 Discuss🧪 Playground+125 XP
Task
📝 **Question:** Predict the output. The test recomputes the HMAC with the same secret + timestamp + body, then compares — it must match (both sides used identical inputs). 📋 Pick the right answer. 💡 **Hint:** Re-read the theory above if unsure.

Keep going

🔮 Predict the output

Read the code carefully

import hmac, hashlib

def verify_signature(secret, body, timestamp, signature):
    payload = f'{timestamp}.'.encode() + body
    expected = hmac.new(secret.encode(), payload, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, signature)

secret = 'whsec_test'
body = b'{"id":"evt_1"}'
ts = '1700000000'
expected = hmac.new(secret.encode(), f'{ts}.'.encode() + body, hashlib.sha256).hexdigest()
print(verify_signature(secret, body, ts, expected))

What will the program print? Write here:

📣 Help someone learn PythonShare this lesson with a friend — the first 15 are free, no signup.Tweet

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…