/** * Determine if the MAC for the given payload is valid. * * @param array $payload * @return bool * * @throws \RuntimeException */ protected function validMac(array $payload) { $bytes = Str::randomBytes(16); $calcMac = hash_hmac('sha256', $this->hash($payload['iv'], $payload['value']), $bytes, true); return Str::equals(hash_hmac('sha256', $payload['mac'], $bytes, true), $calcMac); }