1 | <?php |
||
17 | class HashHmac |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Hashing Algorithm. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | private $algorithm; |
||
26 | |||
27 | /** |
||
28 | * Private Key. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $privateKey; |
||
33 | |||
34 | private $payload; |
||
35 | |||
36 | /** |
||
37 | * Date Time Zone. |
||
38 | * |
||
39 | * @var \DateTimeZone |
||
40 | */ |
||
41 | private $timezone; |
||
42 | |||
43 | /** |
||
44 | * BasicAuth constructor. |
||
45 | * |
||
46 | * @param string $privateKey |
||
47 | * @param string $algo |
||
48 | * @param string $timezone |
||
49 | */ |
||
50 | public function __construct($privateKey, $algo = 'sha512', $timezone = 'UTC') |
||
56 | |||
57 | 19 | /** |
|
58 | 19 | * Creates hash from payload. |
|
59 | 19 | * |
|
60 | 19 | * @param array $payload |
|
61 | * @return mixed |
||
62 | */ |
||
63 | public function createHash($algorithm, array $payload = [], $privateKey) |
||
74 | |||
75 | 3 | public function getEncodedHash(array $payload = []){ |
|
79 | 3 | ||
80 | 3 | ||
81 | 3 | /** |
|
82 | * Compare received hash against payload. |
||
83 | 3 | * |
|
84 | * @param $encodedHash |
||
85 | * @param array $payload |
||
86 | * @return bool |
||
87 | * @throws \Exception |
||
88 | */ |
||
89 | public function compareHash($encodedHash, array $payload = []) |
||
107 | 2 | ||
108 | 2 | ||
109 | 2 | /** |
|
110 | 2 | * @param $key |
|
111 | 2 | * @return $this |
|
112 | */ |
||
113 | 2 | public function setPrivateKey($key) |
|
119 | |||
120 | /** |
||
121 | * Return current Algorithm |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | public function getAlgorithm() |
||
129 | 1 | ||
130 | |||
131 | public function getPayload(){ |
||
134 | |||
135 | /** |
||
136 | 2 | * Returns Current Private Key |
|
137 | * |
||
138 | 2 | * @return string |
|
139 | */ |
||
140 | public function getPrivateKey() |
||
144 | |||
145 | /** |
||
146 | 1 | * @param string $hash |
|
147 | * @param string $payloadHash |
||
148 | 1 | * @return bool |
|
149 | * @throws \Exception |
||
150 | */ |
||
151 | public function verifyHash($hash = '', $payloadHash = '') |
||
163 | |||
164 | protected function verifyAlgorithm($algo) |
||
174 | } |
||
175 |
This check looks for function calls that miss required arguments.