PHP8 sodium_crypto_generichash_update

2024-03-17 22:49 更新

(PHP 7 >= 7.2.0, PHP 8)

sodium_crypto_generichash_update — 向哈希添加消息

說明

sodium_crypto_generichash_update(string &$state, string $message): true

將消息追加到內(nèi)部哈希狀態(tài)。

參數(shù) 

state

sodium_crypto_generichash_init() 的返回值。

message

要追加到哈希狀態(tài)的數(shù)據(jù)。

返回值 

總是返回 true。

示例 

示例 #1 sodium_crypto_generichash_update() example

<?php
$messages = [random_bytes(32), random_bytes(32), random_bytes(16)];
$state = sodium_crypto_generichash_init();
foreach ($messages as $message) {
    sodium_crypto_generichash_update($state, $message);
}
$final = sodium_crypto_generichash_final($state);
var_dump(sodium_bin2hex($final));

$allAtOnce = sodium_crypto_generichash(implode('', $messages));
var_dump(sodium_bin2hex($allAtOnce));
?>

以上示例的輸出類似于:

string(64) "e16e28bbbbcc39d9f5b1cbc33c41f1d217808640103e57a41f24870f79831e04"
string(64) "e16e28bbbbcc39d9f5b1cbc33c41f1d217808640103e57a41f24870f79831e04"


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號