oauth - PHP HMAC-SHA1 function not returning "=" as padding character? -
i trying produce hmac-sha1 signature request access token , token secret tumblr api. using hmac_hash() function in php , understanding algorithm should produce "=" padding @ end of signature, signature returned me function never has padding , think why keep receiving following message tumblr : "oauth_signature not match expected value". have tried using several online signature generators test , produce padding , don't bit confused @ point.
here code:
$params = array( 'oauth_callback' => $callback, 'oauth_consumer_key' => $consumer_key, 'oauth_nonce' => $oauth_nonce, 'oauth_ver' => $oauth_ver, 'oauth_signature_method' => $signature_method, 'oauth_timestamp' => $time ); ksort($params); //--------------- build param string $params; end($params); // move internal pointer end of array $lastkey = key($params); ksort($params); $param_string; foreach($params $k=>$v) { $param_string .= rawurlencode(utf8_encode($k))."=".rawurlencode(utf8_encode($v)); if($k != $lastkey) { $param_string .= "&"; } }; // --------------- build signature base string $base_string; $base_string .= rawurlencode(utf8_encode($http_method))."&"; $base_string .= rawurlencode(utf8_encode($url))."&"; $base_string .= rawurlencode(utf8_encode($param_string)); //------------------ build signing key $signing_key; $signing_key .= rawurlencode(utf8_encode($consumer_secret))."&"; //------------------ build signature $signature; $signature = hash_hmac("sha1", $base_string, $signing_key);
i needed change this: $signature = hash_hmac("sha1", $base_string, $signing_key);
to this: $signature = base64_encode(hash_hmac("sha1", $base_string, $signing_key, true));
Comments
Post a Comment