public function fetchResult() { $result = parent::fetchResult(); $all = $result->getAll(); foreach ($all as $key => $row) { $all[$key] = array('key' => $row['key'], 'data' => $this->cypher->decrypt($row['data'], $this->symmetricKey)); } $result = new ArrayResult($all); return $result; }
protected function extractPayload($data) { // Check if values exist if (!isset($data['gid']) || !is_string($data['gid']) || !preg_match('#^[a-f0-9]*$#', $data['gid'])) { return false; } if ($this->userGID !== null && $this->userGID !== $data['gid']) { return false; } if (!isset($data['hmac']) || !is_string($data['hmac'])) { return false; } $parsed = $this->gid->decode($data['gid']); if (!$parsed || $parsed['type'] !== $this->gid->getType('user')) { return false; } if ($data['payload'] === null) { return null; } // Extract values $expires = $data['expires']; $gid = $data['gid']; $hmac = $data['hmac']; // Create the key $key = $this->createKey($gid, $expires); // Decrypt the (base64 encoded and serialized) data $decrypted = $this->symmetricCypher->decrypt($data['payload'], $key); // Check HMAC $calculatedHMAC = $this->createHMAC($gid, $decrypted, $expires, $key); if ($calculatedHMAC !== $hmac) { return false; } // Decode data $base64decodedData = base64_decode($decrypted); if ($base64decodedData === false) { return false; } try { $extractedData = unserialize($base64decodedData); } catch (Exception $e) { return false; } // Store GID $this->gid = $gid; // Return the payload return $extractedData['payload']; }