hash_hmac
(PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL hash >= 1.1)
hash_hmac — 使用 HMAC 方法產生帶有金鑰的雜湊值
說明
   hash_hmac(
string
string
string
bool
): string
 string
$algo,string
$data,string
$key,bool
$raw_output = false): string
參數
- 
algo
- 
      要使用的雜湊演算法名稱,例如:"md5","sha256","haval160,4" 等。 如何獲取受支援的演算法清單,請參見 hash_hmac_algos() 函式。 
- 
data
- 
      要進行雜湊運算的訊息。 
- 
key
- 
      使用 HMAC 產生資訊摘要時所使用的金鑰。 
- 
raw_output
- 
      設定為 true輸出原始二進制數據, 設定為false輸出小寫 16 進位制字串。
返回值
   如果 raw_output 設定為 true, 則返回原始二進制數據表示的資訊摘要,
   否則返回 16 進位制小寫字串格式表示的資訊摘要。
   如果 algo 參數指定的不是受支援的演算法,返回 false。
  
更新日誌
| 版本 | 說明 | 
|---|---|
| 7.2.0 | 不再支援非加密的雜湊函式(adler32,crc32,crc32b,fnv132,fnv1a32,fnv164,fnv1a64,joaat)。 | 
範例
示例 #1 hash_hmac() 例程
<?php
echo hash_hmac('ripemd160', 'The quick brown fox jumped over the lazy dog.', 'secret');
?>
以上例程會輸出:
b8e7ae12510bdfb1812e463a7f086122cf37e4f7
參見
- hash() - 產生雜湊值 (訊息摘要)
- hash_hmac_algos() - Return a list of registered hashing algorithms suitable for hash_hmac
- hash_init() - 初始化增量雜湊運算上下文
- hash_hmac_file() - 使用 HMAC 方法和給定檔案的內容產生帶金鑰的雜湊值