diff --git a/app/Models/PrivateKey.php b/app/Models/PrivateKey.php index 80015d87f..0e702e460 100644 --- a/app/Models/PrivateKey.php +++ b/app/Models/PrivateKey.php @@ -40,6 +40,8 @@ class PrivateKey extends BaseModel 'private_key' => 'encrypted', ]; + protected $appends = ['public_key']; + protected static function booted() { static::saving(function ($key) { @@ -64,6 +66,11 @@ class PrivateKey extends BaseModel }); } + public function getPublicKeyAttribute() + { + return self::extractPublicKeyFromPrivate($this->private_key) ?? 'Error loading private key'; + } + public function getPublicKey() { return self::extractPublicKeyFromPrivate($this->private_key) ?? 'Error loading private key'; @@ -208,15 +215,14 @@ class PrivateKey extends BaseModel { try { $key = PublicKeyLoader::load($privateKey); - $publicKey = $key->getPublicKey(); - return $publicKey->getFingerprint('sha256'); + return $key->getPublicKey()->getFingerprint('sha256'); } catch (\Throwable $e) { return null; } } - private static function fingerprintExists($fingerprint, $excludeId = null) + public static function fingerprintExists($fingerprint, $excludeId = null) { $query = self::query() ->where('fingerprint', $fingerprint)