Current location - Quotes Website - Personality signature - How to use the key in the shell to generate a signature for the string txt through hmac-sha 1 algorithm?
How to use the key in the shell to generate a signature for the string txt through hmac-sha 1 algorithm?
How to use the key in the shell to generate a signature for the string txt through hmac-sha 1 algorithm?

/**

* @brief uses HMAC-SHA 1 algorithm to generate the signature value of oauth_signature.

*

* @param $key key

* @ param$str source string

*

* @ Returns the signature value

*/

The function getSignature($str, $key) {

$ signature =

if(function _ exists(' hash _ hmac '){

$ signature = base64 _ encode(hash _ hmac(" sha 1 ",$str,$key,true));

} Otherwise {

$ blocksize = 64

$ hash func = ' sha 1 ';

if (strlen($key)>$blocksize) {

$key = pack('H* ',$ hash func($ key));

}

$key = str_pad($key,$blocksize,chr(0x 00));

$ipad = str_repeat(chr(0x36),$ blocksize);

$opad = str_repeat(chr(0x5c),$ blocksize);

$hmac = pack(

H* ',$hashfunc(

($ base $ opad). Packaging (

H* ',$hashfunc(

($ base $ ipad). $str

)

)

)

);

$ signature = base64 _ encode($ hmac);

}

return $ signature

}