Detailed description using the HMAC-SHA1 signature method. Encryption Algorithm: Copy the code using the HMAC-SHA1 signature method: *** @ brief use the HMAC-SHA1 algorithm to generate the oauth_signature signature Value *** @ param $ key * @ param $ str Source string
Encryption Algorithm:
Using the HMAC-SHA1 signature method
The code is as follows:
/**
* @ Brief use the HMAC-SHA1 algorithm to generate the oauth_signature signature value
*
* @ Param $ key
* @ Param $ str Source string
*
* @ Return signature value
*/
Function getSignature ($ str, $ key ){
$ Signature = "";
If (function_exists ('hash _ hmac ')){
$ Signature = base64_encode (hash_hmac ("sha1", $ str, $ key, true ));
} Else {
$ 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). $ str
)
)
)
);
$ Signature = base64_encode ($ hmac );
}
Return $ signature;
}
Pipeline uses the HMAC-SHA1 signature method code as follows:/*** @ brief uses the HMAC-SHA1 algorithm to generate the oauth_signature signature value ** @ param $ key * @ param $ str Source string...