Skip to content

Instantly share code, notes, and snippets.

@chinlung
Last active March 2, 2020 09:51
Show Gist options
  • Save chinlung/94a5a854afd3b6eae8178eef3e69c127 to your computer and use it in GitHub Desktop.
Save chinlung/94a5a854afd3b6eae8178eef3e69c127 to your computer and use it in GitHub Desktop.
Used to encode a field for Auth #hex2b64 #php
function hex2b64($str)
{
$raw = '';
for ($i = 0; $i < strlen($str); $i += 2) {
$raw .= chr(hexdec(substr($str, $i, 2)));
}
return base64_encode($raw);
}
/*
Example:
$signature = hex2b64(hash_hmac('sha1', $data, $secret_key));
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment