Skip to content

Instantly share code, notes, and snippets.

@m-primo
Last active October 3, 2022 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save m-primo/3e1892f4efa3f2c1b7b841c1e3ce12b7 to your computer and use it in GitHub Desktop.
Save m-primo/3e1892f4efa3f2c1b7b841c1e3ce12b7 to your computer and use it in GitHub Desktop.
Hash & Verify - sha512 & hex.. php
function hash_hex_sha512($s) {
return bin2hex(hash('sha512', $s.bin2hex($s), true));
}
function verify_hex_sha512($s, $h) {
return (hash_hex_sha512($s) == $h);
}
$s = "hello there";
$h = hash_hex_sha512($s);
var_dump($h);
var_dump(verify_hex_sha512($s, $h));
final class HexSHA512 {
public static final function Hash($s) {
return (bin2hex(hash('sha512', $s.bin2hex($s), true)));
}
public static final function Verify($s, $h) {
return (HexSHA512::Hash($s) == $h);
}
}
$s = "hello there";
$h = HexSHA512::Hash($s);
var_dump($h);
var_dump(HexSHA512::Verify($s, $h));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment