Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Implement HMAC From Scratch

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Implement HMAC From Scratch. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Implement HMAC from scratch in your preferred language.

Implement hmac_sha256(key, message), treating both inputs as UTF-8 strings and returning the lowercase hexadecimal HMAC-SHA256 digest. Use a 64-byte SHA-256 block size, hash keys longer than one block, and apply the standard inner and outer padding constants.

Constraints

  • 0 <= len(key) <= 10^5 characters
  • 0 <= len(message) <= 10^6 characters
  • Inputs contain valid Unicode strings
  • Use SHA-256 as the underlying hash
  • Return exactly 64 lowercase hexadecimal characters

Function Signature

def hmac_sha256(key, message):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output