Created
October 12, 2021 03:28
-
-
Save danhawkins/558cb06efed44db33863b69d4f345ddd to your computer and use it in GitHub Desktop.
HMAC digest encoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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