id; } /** * @return string */ public function getType() { return $this->type; } /** * @return string */ public function getUse() { return $this->usage; } /** * @return bool */ public function isActive() { return (bool)$this->active; } /** * @return \DateTime */ public function getLastUse() { return $this->last_use; } /** * @return $this */ public function markAsUsed() { $this->last_use = new DateTime(); return $this; } /** * @return string */ public function getKeyId() { return $this->kid; } private function calculateThumbprint($alg) { $res = ''; try { $pem = str_replace(array("\n", "\r"), '', trim($this->getPublicKeyPEM())); $res = strtoupper(hash($alg, base64_decode($pem))); } catch(Exception $ex) { $res = 'INVALID'; } return $res; } /** * @return string */ public function getSHA_1_Thumbprint() { return $this->calculateThumbprint('sha1'); } /** * @return string */ public function getSHA_256_Thumbprint() { return $this->calculateThumbprint('sha256'); } abstract public function getPublicKeyPEM(); /** * @return string */ public function getPEM() { return $this->pem_content; } /** * checks validity range with now * @return bool */ public function isExpired() { $now = new DateTime(); return ( $this->valid_from <= $now && $this->valid_to >= $now); } /** * algorithm intended for use with the key * @return ICryptoAlgorithm */ public function getAlg() { $algorithm = DigitalSignatures_MACs_Registry::getInstance()->get($this->alg); if(is_null($algorithm)) { $algorithm = KeyManagementAlgorithms_Registry::getInstance()->get($this->alg); } return $algorithm; } }