(PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL hash >= 1.1)
hash_init — 初始化增量哈希運(yùn)算上下文
$algo
, int $options
= 0, string $key
= null
): HashContext
algo
要使用的哈希算法名稱,例如:"md5","sha256","haval160,4" 等。 如何獲取受支持的算法清單,請(qǐng)參見(jiàn) hash_algos()。
options
進(jìn)行哈希運(yùn)算的可選設(shè)置,目前僅支持一個(gè)選項(xiàng):HASH_HMAC
。
當(dāng)指定此選項(xiàng)的時(shí)候,必須 指定 key
參數(shù)。
key
當(dāng) options
參數(shù)為 HASH_HMAC
時(shí),
使用此參數(shù)傳入進(jìn)行 HMAC 哈希運(yùn)算時(shí)的共享密鑰。
返回哈希運(yùn)算上下文對(duì)象,以供 hash_update(), hash_update_stream(),hash_update_file(), 和 hash_final() 函數(shù)使用。
版本 | 說(shuō)明 |
---|---|
7.2.0 | 當(dāng)使用 HASH_HMAC 選項(xiàng)的時(shí)候,不再支持非加密的哈希函數(shù)(adler32,crc32,crc32b,fnv132,fnv1a32,fnv164,fnv1a64,joaat)。 |
7.2.0 | 返回 HashContext 對(duì)象,不再返回資源類型。 |
示例 #1 增量哈希運(yùn)算例程
<?php
$ctx = hash_init('md5');
hash_update($ctx, 'The quick brown fox ');
hash_update($ctx, 'jumped over the lazy dog.');
echo hash_final($ctx);
?>
以上例程會(huì)輸出:
5c6ffbdd40d9556b73a21e63c3e0e904