created = new \DateTime(); $this->regeneratePublicKey(); $this->publicVisible = false; $this->publicOpen = false; } private function generateToken($length = 64){ $hash = ""; while(strlen($hash) < $length){ try { $hash .= hash('sha512', random_bytes($length)); } catch (\Exception $e) { $hash .= hash('sha512', mt_rand(0,$length*10000)); } } return substr($hash, 0,$length); } /** * use to change the pk if its not unique */ public function regeneratePublicKey(){ $this->publicKey = $this->generateToken(); } public function setDefault(string $name = "") { $this->name = $name; } /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * Set name * * @param string $name * * @return $this */ public function setName($name) { $this->name = $name; return $this; } /** * Get name * * @return string|null */ public function getName(): ?string { return $this->name; } /** * @return \DateTime */ public function getCreated(): \DateTime { return $this->created; } /** * @return string */ public function getPublicKey(): string { return $this->publicKey; } /** * @param bool $publicVisible * @return $this */ public function setPublicVisible(bool $publicVisible) { $this->publicVisible = $publicVisible; return $this; } /** * @return bool */ public function isPublicVisible(): bool { return $this->publicVisible; } /** * @param bool $publicOpen * @return $this */ public function setPublicOpen(bool $publicOpen) { $this->publicOpen = $publicOpen; return $this; } /** * @return bool */ public function isPublicOpen(): bool { return $this->publicOpen; } }