Signatur
hash_hmac(string $algo, string $data, string $key, bool $binary = false): string
Beschreibung
HMAC = Hash-based Message Authentication Code. Verhindert Manipulation und beweist Authentizität.
Parameter
| Name | Typ | Default | Beschreibung |
|---|---|---|---|
| $algo Pflicht | string | — | Algorithmus. |
| $data Pflicht | string | — | Daten. |
| $key Pflicht | string | — | Geheimer Schlüssel. |
| $binary | bool | false | Binär statt Hex. |
Rückgabewert
Typ
string
Beschreibung
HMAC.
Beispiele
Webhook-Signatur prüfen
<?php
$expected = hash_hmac('sha256', $payload, $secret);
if (!hash_equals($expected, $_SERVER['HTTP_X_SIGNATURE'])) {
http_response_code(401);
exit;
}