Created
June 30, 2021 11:54
-
-
Save MattHealy/0b2da711cde4612b76e26eabfbd79ce3 to your computer and use it in GitHub Desktop.
PHP HMAC-SHA512 example
This file contains 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
<?php | |
// HMAC-SHA512 signing | |
function get_signature($event, $orderid, $listing_id) { | |
// Hashing algorithm to use | |
$algo = 'sha512'; | |
// Shared key used for signing payloads | |
$secret_key = 'abcdef'; | |
// Number of milliseconds since epoch | |
$timestamp = time() * 1000; | |
// Payload to be signed | |
$payload = "t=$timestamp&event=$event&orderid=$orderid&listing_id=$listing_id"; | |
// Generate the signed payload | |
$signed_payload = hash_hmac( | |
$algo, | |
$payload, | |
$secret_key, | |
false, | |
); | |
return "t=$timestamp,$algo=$signed_payload"; | |
} | |
$sig = get_signature("delivery", "12345", "L98765"); | |
echo $sig . "\n"; | |
// Include this value as a header in the request | |
// curl 'http://partner.se/diakrit/notify.php?event=change&orderid=XXXXXXX&listing_id=XXXXXXXX' -H 'X-DIAKRIT-SIGNATURE: sig' | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment