Base de connaissancesCentre d’examen
FRFrançais
Choisir la langue13

CKTIS / PHP

hash()

Calcule l’empreinte des octets exacts avec l’algorithme choisi.

Version : PHP 8.4; repository runtime, production runtime not attested

Syntaxe

hash(string $algo, string $data, bool $binary = false, array $options = []): string

Calcule l’empreinte des octets exacts avec l’algorithme choisi. Le résultat normal est un texte hexadécimal en minuscules. En mode binaire SHA-256 fournit 32 octets au lieu de 64 caractères. Un algorithme inconnu déclenche ValueError en PHP 8.

Signature

hash(string $algo, string $data, bool $binary = false, array $options = []): string

Sortie de l’exemple

["ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",32,true]

Exemples

<?php
$hex=hash("sha256","abc"); $raw=hash("sha256","abc",true);
echo json_encode([$hex,strlen($raw),bin2hex($raw)===$hex]);

Résultat

["ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",32,true]

Sources