php對應C hmac sha1演算法 (OAuth 1.0 加密生成oauth_signature 需要)
阿新 • • 發佈:2019-02-15
function oauth_hmacsha1($key, $data) { return base64_encode(hmacsha1($key, $data)); } 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; }