17 lines
482 B
PHP
17 lines
482 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace App\Security;
|
|
|
|
final class Hmac
|
|
{
|
|
public static function sign(string $secret, string $nonce, string $ts, string $body): string
|
|
{
|
|
return hash_hmac('sha256', $nonce . $ts . $body, $secret);
|
|
}
|
|
|
|
public static function verify(string $secret, string $nonce, string $ts, string $body, string $sig): bool
|
|
{
|
|
$expected = self::sign($secret, $nonce, $ts, $body);
|
|
return hash_equals($expected, $sig);
|
|
}
|
|
}
|