//ads:
?>
Unable to match results of php hash_hmac() and coldfusion hmac()
PHP Snippet 1:
<cfscript>
key = '943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881';
salt = '520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5';
keyBin = binaryDecode(key, "hex");
saltBin = binaryDecode(salt, "hex");
path = "/rs:fill:300:300:1/g:no/aHR0cDovL2ltZy5leGFtcGxlLmNvbS9wcmV0dHkvaW1hZ2UuanBn.png";
pathBin = charsetDecode(path, "utf-8");
// merge binary of salt and path
combined = [];
combined.append(saltBin, true);
combined.append(pathBin, true);
result = lcase(hmac( javacast("byte[]", combined),keyBin,"HMACSHA256"));
writeDump(result);
</cfscript>
PHP Snippet 2:
<?php
$key = '943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881';
$salt = '520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5';
$keyBin = pack("H*" , $key);
$saltBin = pack("H*" , $salt);
$path = "/rs:fill:300:300:1/g:no/aHR0cDovL2ltZy5leGFtcGxlLmNvbS9wcmV0dHkvaW1hZ2UuanBn.png";
echo hash_hmac('sha256', $saltBin.$path, $keyBin);