Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / PHP

hash()

Calcola l’impronta dei byte esatti con l’algoritmo scelto.

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

Sintassi

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

Calcola l’impronta dei byte esatti con l’algoritmo scelto. Per impostazione predefinita restituisce testo esadecimale minuscolo. In modalità binaria SHA-256 dà 32 byte invece di 64 caratteri. Un algoritmo non supportato causa ValueError in PHP 8.

Firma

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

Output dell’esempio

["ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",32,true]

Esempi

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

Risultato

["ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",32,true]

Fonti