getLength() < 2048) { throw new Exception('RSA keys must be at least 2048 bytes in length'); } $fingerprint = $key->getFingerprint('sha256'); if ($user->sshKeys()->where('fingerprint', $fingerprint)->exists()) { throw new Exception('The public key provided already exists on your account'); } /** @var UserSSHKey $sshKey */ $sshKey = $user->sshKeys()->create([ 'name' => $name, 'public_key' => $key->toString('PKCS8'), 'fingerprint' => $fingerprint, ]); return $sshKey; } }