hash_final
结束增量哈希,并且返回摘要结果
PHP 5.1.2 及以上版本。
hash_final 函数用于返回通过 hash_update 处理的数据的最终哈希值。该函数常用于获取哈希计算完成后的最终值,通常与其他哈希相关函数(如 hash_init 和 hash_update)一起使用。
string hash_final ( resource $context [, bool $raw_output = false ] )
返回计算后的哈希值。如果提供了 $raw_output 参数并将其设置为 true,返回的是原始二进制数据。如果为 false,则返回十六进制的哈希值字符串。
以下是一个简单的使用 hash_final 函数的示例:
<?php
// 初始化哈希上下文
$context = hash_init('sha256');
<p>// 更新哈希数据<br>
hash_update($context, 'Hello, world!');</p>
<p>// 获取最终哈希值<br>
$hash = hash_final($context);</p>
<p>// 输出哈希值<br>
echo $hash;<br>
?><br>
在上面的示例中,首先使用 hash_init 函数初始化一个 SHA-256 的哈希上下文。接着,通过 hash_update 函数向该上下文添加数据。最后,使用 hash_final 函数获取最终的哈希值,并将其输出。