Skip to content

Instantly share code, notes, and snippets.

Created September 24, 2014 15:32
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save turret-io/af31732a7ade127b48e3 to your computer and use it in GitHub Desktop.
Generate HMAC in PHP
define("SHARED_SECRET", "sup3rs3cr3t!!");
function signString($string_to_sign, $shared_secret) {
return hash_hmac("sha512", $string_to_sign, $shared_secret);
$payload = array(
'name' => 'joe smith',
'category' => 'people',
'action' => 'transport',
'where' => 'pluto',
'timestamp' => time()
$json_payload = json_encode($payload);
$signature = signString($json_payload, SHARED_SECRET);
$encoded_signature = base64_encode($signature);
$encoded_payload = base64_encode($json_payload);
echo "/?data={$encoded_payload}&signature={$encoded_signature}\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment