| 1 |
<?php |
| 2 |
|
| 3 |
namespace ElementorDeps\Laravel\SerializableClosure\Signers; |
| 4 |
|
| 5 |
use ElementorDeps\Laravel\SerializableClosure\Contracts\Signer; |
| 6 |
class Hmac implements Signer |
| 7 |
{ |
| 8 |
/** |
| 9 |
* The secret key. |
| 10 |
* |
| 11 |
* @var string |
| 12 |
*/ |
| 13 |
protected $secret; |
| 14 |
/** |
| 15 |
* Creates a new signer instance. |
| 16 |
* |
| 17 |
* @param string $secret |
| 18 |
* @return void |
| 19 |
*/ |
| 20 |
public function __construct($secret) |
| 21 |
{ |
| 22 |
$this->secret = $secret; |
| 23 |
} |
| 24 |
/** |
| 25 |
* Sign the given serializable. |
| 26 |
* |
| 27 |
* @param string $serialized |
| 28 |
* @return array |
| 29 |
*/ |
| 30 |
public function sign($serialized) |
| 31 |
{ |
| 32 |
return ['serializable' => $serialized, 'hash' => \base64_encode(\hash_hmac('sha256', $serialized, $this->secret, \true))]; |
| 33 |
} |
| 34 |
/** |
| 35 |
* Verify the given signature. |
| 36 |
* |
| 37 |
* @param array $signature |
| 38 |
* @return bool |
| 39 |
*/ |
| 40 |
public function verify($signature) |
| 41 |
{ |
| 42 |
return \hash_equals(\base64_encode(\hash_hmac('sha256', $signature['serializable'], $this->secret, \true)), $signature['hash']); |
| 43 |
} |
| 44 |
} |
| 45 |
|