/** * Calculate the signature using MD5 * Binary md5 digest, as distinct from PHP's built-in hexdigest. * This function is copyright Andy Smith, 2007. * * @param OAuthRequest request * @param string base_string * @param string consumer_secret * @param string token_secret * @return string */ function signature(IOauthSignable $reponse, Secrets $secrets, $data = null) { //$s .= '&'.$reponse->oauthurlencode($secrets->consumer_secret).'&'.$reponse->oauthurlencode($secrets->token_secret); To nedava smysl a navic to hazi chybu $md5 = md5($data !== null ? $data : $reponse->getSignatureBaseString()); $bin = ''; for ($i = 0; $i < strlen($md5); $i += 2) { $bin .= chr(hexdec($md5[$i + 1]) + hexdec($md5[$i]) * 16); } return $reponse->oauthurlencode(base64_encode($bin)); }
/** * Calculate the signature using HMAC-SHA1 * This function is copyright Andy Smith, 2007. * * @param OAuthRequest request * @param string base_string * @param string consumer_secret * @param string token_secret * @return string */ function signature(IOauthSignable $response, Secrets $secrets, $data = null) { $key = $response->oauthurlencode($secrets->consumer_secret) . '&' . $response->oauthurlencode($secrets->token_secret); if (function_exists('hash_hmac')) { $signature = base64_encode(hash_hmac("sha1", $data !== null ? $data : $response->getSignatureBaseString(), $key, true)); } else { $blocksize = 64; $hashfunc = 'sha1'; if (strlen($key) > $blocksize) { $key = pack('H*', $hashfunc($key)); } $key = str_pad($key, $blocksize, chr(0x0)); $ipad = str_repeat(chr(0x36), $blocksize); $opad = str_repeat(chr(0x5c), $blocksize); $hmac = pack('H*', $hashfunc(($key ^ $opad) . pack('H*', $hashfunc(($key ^ $ipad) . $response->getSignatureBaseString())))); $signature = base64_encode($hmac); } return $response->oauthurlencode($signature); }