This article is the use of HMAC-SHA1 signature method for a detailed analysis of the introduction, need a friend reference
This article is the use of HMAC-SHA1 signature method for a detailed analysis of the introduction, need a friend reference
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;
}
, Server space, Hong Kong Space, Hong Kong Space