Files
ladill-servers/app/Services/Infrastructure/ContaboInfrastructureSshKeyService.php
T
isaaccladandCursor b6c8ac343f Extract Ladill Servers as standalone app at servers.ladill.com.
VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-06 19:18:30 +00:00

35 lines
886 B
PHP

<?php
namespace App\Services\Infrastructure;
class ContaboInfrastructureSshKeyService
{
/**
* @return array{public_key: string, private_key: string}
*/
public function generate(): array
{
$resource = openssl_pkey_new([
'private_key_bits' => 4096,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
]);
if ($resource === false) {
throw new \RuntimeException('Failed to generate SSH key pair.');
}
openssl_pkey_export($resource, $privateKey);
$details = openssl_pkey_get_details($resource);
$publicKey = $details['key'] ?? '';
if ($publicKey === '') {
throw new \RuntimeException('Failed to export SSH public key.');
}
return [
'public_key' => trim($publicKey)."\n",
'private_key' => $privateKey,
];
}
}