PHP - Hash final() 函式



定義和用法

hash_final() 函式返回最終的訊息摘要。

訊息摘要是一個使用雜湊演算法生成的包含小寫十六進位制數的雜湊值。它主要用於確保資料安全,防止傳送的訊息或資料被篡改。

語法

hash_final ( HashContext $context [, bool $raw_output = FALSE ] ) : string

引數

序號 引數和描述
1

HashContext context

使用 hash_init() 獲取的雜湊上下文。

2

raw_output

接受 true 或 false 作為值。如果為 true,則返回小寫十六進位制數,否則返回原始二進位制資料。預設值為 true。

返回值

PHP hash_final() 函式返回一個字串,其中包含計算出的訊息摘要(小寫十六進位制數)。如果將 false 傳遞給 raw_output,則輸出將是一個包含原始二進位制資料的字串。

PHP 版本

此函式在 PHP 5.1.2 及更高版本中可用。

示例 1

使用 hash_final -

<?php
   $hash_context = hash_init('md5');
   hash_update($hash_context, 'Testing php');
   hash_update($hash_context, ' hash functions.');
   echo hash_final($hash_context);
?>

輸出

這將產生以下結果 -

e4310012c89a4b8479fd83694a2a3a31

示例 2

將 raw_output 設定為 true 使用 hash_final -

<?php
   $hash_context = hash_init('md5');
   hash_update($hash_context, 'Testing php');
   echo hash_final($hash_context, true); 
?>
php_function_reference.htm
廣告