Skip to content

Instantly share code, notes, and snippets.

@raphaelsaunier
Created February 2, 2012 17:55
Show Gist options
  • Save raphaelsaunier/1724857 to your computer and use it in GitHub Desktop.
Save raphaelsaunier/1724857 to your computer and use it in GitHub Desktop.
validate_hash.php
<?php
$key = 'our passphrase here';
$hash = 'f8956ba8af19b58e6a92e234abfebf13';
// Encryption function we'll use on our side. This would be retrieved as $_POST['signature'] on your side.
$signature = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $hash, MCRYPT_MODE_CBC, md5(md5($key))));
$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($signature), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
if($hash == $decrypted)
{
// The hash is valid..
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment