SecurityProvider.php
980 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/* ===========================================================================
* Copyright (c) 2018-2021 Zindex Software
*
* Licensed under the MIT License
* =========================================================================== */
namespace Opis\Closure;
class SecurityProvider implements ISecurityProvider
{
/** @var string */
protected $secret;
/**
* SecurityProvider constructor.
* @param string $secret
*/
public function __construct($secret)
{
$this->secret = $secret;
}
/**
* @inheritdoc
*/
public function sign($closure)
{
return array(
'closure' => $closure,
'hash' => base64_encode(hash_hmac('sha256', $closure, $this->secret, true)),
);
}
/**
* @inheritdoc
*/
public function verify(array $data)
{
return base64_encode(hash_hmac('sha256', $data['closure'], $this->secret, true)) === $data['hash'];
}
}