Home >Backend Development >PHP Tutorial >Detailed explanation of using HMAC-SHA1 signature method_PHP tutorial

Detailed explanation of using HMAC-SHA1 signature method_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:02:311201browse

Encryption algorithm:
Use HMAC-SHA1 signature method

Copy code The code is as follows:

/**
* @brief Use HMAC-SHA1 algorithm to generate oauth_signature signature value
*
* @param $key 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));
                                                                                                                            ) > $blocksize) {
                      $key = pack('H*', $hashfunc($key)); );
$ipad = str_repeat(chr(0x36), $blocksize);
$opad = str_repeat(chr(0x5c), $blocksize);
$hmac = pack(
          'H* ', $hashfunc(
($key ^ $opad) . pack(
'H*', $hashfunc(
($key ^ $ipad) . $str
                                         
                                                                              🎜>





http://www.bkjia.com/PHPjc/327907.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/327907.html

TechArticle

Encryption algorithm: Use HMAC-SHA1 signature method to copy the code The code is as follows: /** * @brief Use HMAC-SHA1 Algorithm generates oauth_signature signature value* * @param $key key* @param $str source string...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn