sha256 - Generate HMAC Signature on PHP

766

how do you apply the system below to php?

StringToSign = HTTPMethod+":"+RelativeUrl+":"+AccessToken+":"+
Lowercase(HexEncode(SHA-256(RequestBody)))+":"+Timestamp

Signature = HMAC-SHA256(apiSecret, StringToSign)

my script :

$encoderData = json_encode($bodyToHash, JSON_UNESCAPED_SLASHES);
$hash        = hash("sha256", $encoderData);
$stringToSign   = $Method. ":" .$url . ":" . $auth_token . ":" . $hash . ":" . $Timestamp;
$auth_signature = hash_hmac('sha256', $secret_key, $stringToSign,false);

Thank you,

190

Answer

Solution:

I don't know what you mean but You can try this;

<?php
    $stringToSign = 'abcd';
    $apiSecret = 'secretkey';

    $hashed = hash_hmac('sha256', $stringToSign, $apiSecret);
?>
250

Answer

Solution:

doing some BCA stuff? :p

you can use this function if you wan to useGET:

strtolower(hash('sha256', ''));

People are also looking for solutions to the problem: session - PHP header working on localhost but not on live server

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.