title: attempting to verify a webhook secret with hmac and sha256
body: <p>so I am a little confused here.</p>
  <p>I am using a api that sends a webhook to my server. It allows us to verify the request came from the api.</p>
  <p>I am using django rest framework.</p>
  <p>the signature comes over like this as an example</p>
  <p><code>Mux-Signature: t=1565220904,v1=20c75c1180c701ee8a796e81507cfd5c932fc17cf63a4a55566fd38da3a2d3d2 </code>
  the value after the t= is a time stamp. The value after v1= is the signature</p>
  <pre><code>muxsecurityheader = request.META['HTTP_MUX_SIGNATURE']
          spiltmuxsecurityheader = muxsecurityheader.split(',')
          timestamp = spiltmuxsecurityheader[0]
          timestamp = timestamp[2:]
          receviedsignature = spiltmuxsecurityheader[1]
          receviedsignature = receviedsignature[3:]
          secretkey = 'a string that is my key'
          payload = timestamp + '.' + str(request.body)
          expectedsignature = hmac.new(secretkey, bytes(payload, 'UTF-8'), hashlib.sha256).hexdigest()
          print(expectedsignature)
  </code></pre>
  <p>is the code I have so far.</p>
  <p>in an example on the apis docs <a href="https://docs-legacy.mux.com/docs/webhook-security" rel="nofollow noreferrer">https://docs-legacy.mux.com/docs/webhook-security</a></p>
  <p>it states to determine the expected signature by the provided example. Obviously this is just pseudocode</p>
  <pre><code>secret = // your signing secret
  payload = timestamp + &quot;.&quot; + request_body
  expected_signature = createHmacSha256(payload, secret)
  </code></pre>
  <p>which is similar to the code I have above.</p>
  <p>however I am getting a few errors and</p>
  <pre><code>expectedsignature = hmac.new(secretkey, bytes(payload, 'UTF-8'), hashlib.sha256).hexdigest()
  raise TypeError(&quot;key: expected bytes or bytearray, but got %r&quot; % type(key).__name__)
  TypeError: key: expected bytes or bytearray, but got 'str'
  </code></pre>
  <p>is one of them.</p>
  <p>for example is one that I am trying to solve. And Im at the point where one of you is going to instantly see what It is I am doing wrong. I really appreciate you providing some clarity.</p>