OAuth签名

时间:2011-07-19 09:35:57

标签: php oauth digital-signature

我正在尝试设置自己的OAuth提供程序,但现在我一直在签署请求。这是签署的正确方式吗?

function generateSignature($consumerSecret, $requestURI, $requestData, $requestMethod) {
    $signature = '';
    $signature .= strtoupper($requestMethod) . '&';
    $signature .= urlencode($requestURI) . '&';
    asort($requestData);
    $query = http_build_query($requestData);
    $signature .= urlencode($query);
    echo oauthHMACsha1($consumerSecret, $signature);

}

function HMACsha1($key, $data) {
    $blocksize = 64;
    $hashfunc = 'sha1';
    if (strlen($key) > $blocksize) $key = pack('H*', $hashfunc($key));
    $key = str_pad($key, $blocksize, chr(0x00));
    $ipad = str_repeat(chr(0x36), $blocksize);
    $opad = str_repeat(chr(0x5c), $blocksize);
    $hmac = pack('H*',$hashfunc(($key^$opad).pack('H*', $hashfunc(($key ^ $ipad) . $data))));
    return $hmac;
}

function oauthHMACsha1($key, $data) {
    return base64_encode(HMACsha1($key, $data));
}

或者它可以更容易/更有效吗?为什么签名很重要?

1 个答案:

答案 0 :(得分:0)

你见过hash_hmac php函数吗?