hash_update

(PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL hash >= 1.1)

hash_update — Ajoute des données dans le contexte de hachage actif

Description

function hash_update(HashContext $context, string $data): true

Liste de paramètres

context

Contexte de hachage retourné par hash_init() .

data

Message qui sera inclus dans l'empreinte de hachage.

Valeurs de retour

Retourne toujours true .

Historique

Version Description
8.4.0 Possède désormais un type de retour true au lieu de bool .
7.2.0 Accepte une HashContext au lieu d'une ressource.

Voir aussi

  • hash_init() - Initialise un contexte de hachage incrémental
  • hash_update_file() - Ajoute des données dans un contexte de hachage actif provenant d'un fichier
  • hash_update_stream() - Ajoute des données dans un contexte de hachage actif d'un flux ouvert
  • hash_final() - Finalise un hachage incrémental et retourne le résultat de l'empreinte numérique

Found A Problem?

Learn How To Improve This Page • Submit a Pull Request • Report a Bug
+add a note

User Contributed Notes 1 note

up
5
Dainichi
20 years ago
A simple example on incremental file hashing:
$fp = fopen($file, "r");
$ctx = hash_init('sha256');
while (!feof($fp)) {
 $buffer = fgets($fp, 65536);
 hash_update($ctx, $buffer);
}
$hash = hash_final($ctx, true);
fclose($fp);
While incremental hashing is quite slow, it's the easiest way to hash 
- parts of large files: I.e., a 700MB avi video uses first x bytes to store metadata, so in order to hash the avi's data only, you have to fseek to data start and use incremental hashing
- streaming data if php just proxies the data
- whenever it's inadequate or impossible to store the data being hashed into memory (i.e. because of their size) or on disc.
+add a note

AltStyle によって変換されたページ (->オリジナル) /