Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save satyendrakumarsingh/29ecd67874760ce7f3bed0140daa9a45 to your computer and use it in GitHub Desktop.
Save satyendrakumarsingh/29ecd67874760ce7f3bed0140daa9a45 to your computer and use it in GitHub Desktop.
PHP function to generate hash value and compare two hash value
<?php
// Defining a generateHash PHP Function
function generateHash($algo, $data, $key) {
return hash_hmac($algo, $data, $key);
}
// Defining a compareHash PHP Function
function compareHash($hashValue1, $hashValue2) {
return hash_equals($hashValue1, $hashValue2);
}
// Calling generateHash()
$hashValue = generateHash('sha256','your message or data', '12dfgW');
echo $hashValue;
// Calling compareHash()
// $hashCompareResult = compareHash($hashValue1, $hashValue2);
// echo $hashCompareResult;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment