Bird
0
0

Which of the following is the correct Python code snippet to compute an HMAC SHA256 signature for webhook verification?

easy📝 Syntax Q12 of 15
Rest API - Webhooks and Events
Which of the following is the correct Python code snippet to compute an HMAC SHA256 signature for webhook verification?
Ahmac.new(secret.encode(), payload.encode(), hashlib.sha256).hexdigest()
Bhmac.new(payload.encode(), secret.encode(), hashlib.md5).hexdigest()
Chashlib.sha256(secret + payload).hexdigest()
Dhmac.sha256(secret, payload).hexdigest()
Step-by-Step Solution
Solution:
  1. Step 1: Understand HMAC function parameters

    The correct order is secret key first, then message (payload), and the hashing algorithm.
  2. Step 2: Identify correct syntax and algorithm

    hmac.new(secret.encode(), payload.encode(), hashlib.sha256).hexdigest() uses hmac.new with secret encoded, payload encoded, and hashlib.sha256, which is correct.
  3. Final Answer:

    hmac.new(secret.encode(), payload.encode(), hashlib.sha256).hexdigest() -> Option A
  4. Quick Check:

    Secret first, payload second, SHA256 used [OK]
Quick Trick: Secret key is first argument in hmac.new() [OK]
Common Mistakes:
MISTAKES
  • Swapping secret and payload order
  • Using wrong hash function like md5
  • Incorrect function call syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes