Hashing, encoding and basic security · 10 / 15 Exercise Hard

Sign messages with HMAC

Objective

A normal hash can be computed by anyone. An HMAC combines the message with a secret key: only someone who knows the key can generate a valid signature. It is used to authenticate requests and cookies.

Instructions

  • The first line has the number n of commands; each one is sign key message (shows the HMAC-SHA256 signature in hexadecimal) or check key message signature. All fields are one word.
  • For check show valid if the signature matches or invalid if not (compare with hmac.compare_digest).
Input
2
sign secreto pedido42
check secreto pedido42 d424d81d28173d1d736e4d702be076d3f6aac548e6e7acd3a11aeb2430a6cbb7
Output
d424d81d28173d1d736e4d702be076d3f6aac548e6e7acd3a11aeb2430a6cbb7
valid

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise