As per the various docs that I have read for using HMAC SHA256, I have understood that:
H (K XOR opad, H (K XOR ipad, text)) where H in my case is SHA256.
But, SHA256 input has only one parameter i.e a Message. Whereas H(K,text) has two inputs. So how to calculate H(k,text)?
Should I first encode text with k and then use H(encoded_text), where encoded_text will be used as a message?
Thank You
HMAC(K,m) = H((K ⊕ opad) ∥ H((K ⊕ ipad) ∥ m)).
Your result would be:
H(o_key_pad || H(i_key_pad || TEXT))
You can find a good read here: http://timdinh.nl/index.php/hmac/
With also the following pseudocode which almost looks like mine :
function hmac (key, message)
opad = [0x5c * blocksize] // Where blocksize is that of the underlying hash function
ipad = [0x36 * blocksize]
if (length(key) > blocksize) then
key = hash(key) // Where 'hash' is the underlying hash function
end if
for i from 0 to length(key) - 1 step 1
ipad[i] = ipad[i] XOR key[i]
opad[i] = opad[i] XOR key[i]
end for
return hash(opad || hash(ipad || message)) // Where || is concatenation
end function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With