Use the HMAC-SHA1 signature method detailed _ PHP Tutorial

Source: Internet
Author: User
Tags hmac
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.