2025-06-03 21:53:49 -04:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Service;
|
|
|
|
|
|
|
|
use Incoviba\Common\Ideal;
|
|
|
|
|
|
|
|
class HMAC extends Ideal\Service
|
|
|
|
{
|
2025-06-03 23:04:57 -04:00
|
|
|
public function validate(string $timestamp, string $requestSignature, string $requestId, string $secret): bool
|
2025-06-03 21:53:49 -04:00
|
|
|
{
|
|
|
|
$message = "{$timestamp}.{$requestId}";
|
|
|
|
$encodedSecret = mb_convert_encoding($secret, 'UTF-8');
|
|
|
|
$encodedMessage = mb_convert_encoding($message, 'UTF-8');
|
|
|
|
$hmacObject = hash_hmac('sha256', $encodedMessage, $encodedSecret);
|
2025-06-03 23:07:47 -04:00
|
|
|
return hash_equals($hmacObject, $requestSignature);
|
2025-06-03 21:53:49 -04:00
|
|
|
}
|
|
|
|
}
|