Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesFastAPI ProductionModule 4 · Async, Background Tasks, WebSocketsHMAC webhook signature verificationpredict52 / 105
+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.
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:

💬 Discussion

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