Encryption Algorithm:
Using the HMAC-SHA1 signature method
Copy codeThe 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;
}