KennisbankExamencentrum
NL · NLNederlands (Nederland)
Taal kiezen13

CKTIS / PHP

hash_hmac()

Authenticeert berichtbytes met een geheime sleutel en cryptografische hashfunctie.

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

Syntax

hash_hmac(string $algo, string $data, string $key, bool $binary = false): string

Authenticeert berichtbytes met een geheime sleutel en cryptografische hashfunctie. Standaard verschijnt hextekst in kleine letters, met true ruwe bytes. Een onbekend of niet-cryptografisch algoritme geeft in PHP 8 ValueError. Controleer met dezelfde sleutel en vorm.

Signatuur

hash_hmac(string $algo, string $data, string $key, bool $binary = false): string

Uitvoer van het voorbeeld

[32,true,false]

Voorbeelden

<?php
$tag=hash_hmac("sha256","batch=42","example-key",true);
echo json_encode([strlen($tag),hash_equals($tag,hash_hmac("sha256","batch=42","example-key",true)),hash_equals($tag,hash_hmac("sha256","batch=43","example-key",true))]);

Resultaat

[32,true,false]

Bronnen