Skip to content

Instantly share code, notes, and snippets.

@RyAndrew
Created January 15, 2019 21:03
Show Gist options
  • Save RyAndrew/1c2c8bdd40adb110fc687abc5727d243 to your computer and use it in GitHub Desktop.
Save RyAndrew/1c2c8bdd40adb110fc687abc5727d243 to your computer and use it in GitHub Desktop.
Authorize.Net PHP API AIM SHA512 Signature HMAC Calculating Example
<?php
echo "<PRE style=\"font-size:24px\">";
$apiLoginId = '65M3HCNw3bp1';
$transactionId = '2018911514592302024';
$transactionAmount = '46.33';
$messageString = "^{$apiLoginId}^{$transactionId}^{$transactionAmount}^";
//Replace with your key!
$key = "9386670063D32DEE0B7918EF5AD6E7C48B9CECC40A5BA6C483A3C1B0D71101C68AB5F7F5BD679D346CDB46DF07EE1E7726CB87FB2B2773A07983F999B07733B1";
$key = pack("H*",$key);
//calculate
$verifyHash = hash_hmac('sha512', $messageString, $key);
$verifyHash = strtoupper($verifyHash);
//This is in the response from their server
$responseHash = 'E8F917A40CAAF588645402E902F2AE810EFF2CEE160086263A5418D671BF2EDB9FB051C1132162F8B04F1CB6B216564CB7DC87DD276D0E24233009B4304561D8';
//FYI this example doesn't match. data has been changed to protect the innocent
if($verifyHash == $responseHash){
echo "YES match!<BR>\r\n";
}else{
echo "NO match!\r\n";
}
echo "their hash:<BR>",$responseHash,"<BR>\r\n";
echo "my hash:<BR>",$verifyHash,"<BR>\r\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment