Last active
October 11, 2017 08:38
-
-
Save paullaffitte/0289cd39e38e6b79bfe1978247a305a2 to your computer and use it in GitHub Desktop.
here is the way we compute digests and compare them with the digests compted by Epoch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function getDigest($flexpost, $source_encoding=null) { | |
if ( array_key_exists('epoch_digest', $flexpost) ) | |
unset($flexpost['epoch_digest']); | |
ksort($flexpost); | |
$sorted_string = urldecode(strtr(http_build_query($flexpost), ['&' => '', '=' => ''])); | |
if ( $source_encoding ) | |
$sorted_string = mb_convert_encoding($sorted_string, self::UTF8_ENCODING, $source_encoding); | |
return hash_hmac('md5', $sorted_string, $this->hmac_key); | |
} | |
public function checkDigest($flexpost) { | |
$digest = $flexpost['epoch_digest']; | |
if ( $digest == $this->getDigest($flexpost) ) | |
return self::UTF8_ENCODING; | |
if ( $digest == $this->getDigest($flexpost, self::WINDOWS_ENCODING) ) | |
return self::WINDOWS_ENCODING; | |
throw new Exception("Bad security digest"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment