hash_hmac
has four parameters and the last one specifies the output and by default hash_hmac
returns hex string, not the raw data. So base64_encode
encodes hex string in the PHP code fragment.
This one will work well:
$payload = "thisisanapple";
$signature = hash_hmac("sha1", $payload, "thisisarandomkey", true);
$data = base64_encode($signature);
// wR7f2bJDVseOan5/AXgsbBLI6eE=