Skip to content

Instantly share code, notes, and snippets.

@danhawkins
Created October 12, 2021 03:28
Show Gist options
  • Select an option

  • Save danhawkins/558cb06efed44db33863b69d4f345ddd to your computer and use it in GitHub Desktop.

Select an option

Save danhawkins/558cb06efed44db33863b69d4f345ddd to your computer and use it in GitHub Desktop.
HMAC digest encoding
$signature_from_header = file_get_contents("example-signature.txt");
$webhook_secret = file_get_contents("example-secret.txt");
$raw_data = file_get_contents("example-payload.json");
// Uses the bitmask value for json encode
// JSON_UNESCAPED_SLASHES => 64
// JSON_UNESCAPED_UNICODE => 256
$json_data = json_encode(json_decode($raw_data),320);
print($json_data);
print("\n");
$calculated_sig = "sha1=" . hash_hmac("sha1", $json_data, $webhook_secret);
print("Calculated Signature: " . $calculated_sig . "\n");
$matching = $calculated_sig == $signature_from_header ? "true" : "false";
print("Matching: " . $matching);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment