I'm trying to verify a signature on a web request. I need to compute an HMAC with the SHA256 hash function using my secret as the key and a signed payload as the message, then compare that with the signature.
The signature looks like this:
0d586561d8f896e52d5c4a2147609fdf74eb72e7bcb3a3756b89fcbef88a94b3
It seems like cryptonite is the right library for this, so I'm using hmac from Crypto.MAC.HMAC. Here's what I have so far:
case digestFromByteString signature of
Nothing -> return False
Just signatureDigest ->
return $ signatureDigest `constEq` hmacGetDigest (hmac secret signedPayload :: HMAC SHA256)
Visually the digest and the signature look the same. If I convert both sides to strings, the strings are equal.
show hmacHash == T.unpack (T.decodeUtf8 signature) -- This is True!
But I can't even get so far as constEq because when I use digestFromByteString to convert the signature string into a digest, it fails. Why?
(Also if I'm barking up the wrong tree on anything else, please let me know.)