Answer the question
In order to leave comments, you need to log in
How to generate HMAC with SHA-256 in PHP correctly?
I deal with the bank - there is the following process - we get the secret key and collect the control line. then, based on this data, we generate an HMAC using the SHA-256 algorithm and thereby sign the payment form.
They issue the secret key in Base64, to generate HMAC it needs to be converted to HEX. HMAC must be sent in base64 (it can be in hex, but base64 is preferable).
In general, in php I wrote like this
$binary = base64_decode($secret);
$hex = strtoupper(bin2hex($binary));
$hmac = base64_encode(hash_hmac('sha256', $stroka, $hex, true));
$hmac = hash_hmac('sha256', '1680024001;80024001;30;5.00', 'AF63D092A79416EC6CA99891EB8CF4E6AFEF5DCE9D6308CBA6A186D03A4B70F3', false);
echo strtoupper($hmac);
Answer the question
In order to leave comments, you need to log in
You forgot to convert the key from hex to binary representation.
PS. It is better to remove the link to the test payments page, for sure you have some kind of NDA signed with the bank for such things.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question