From eb810fcd4c1f05d35be50deaedfc3cbc3636e1d0 Mon Sep 17 00:00:00 2001 From: Constantin Graf Date: Wed, 22 May 2024 15:47:54 +0200 Subject: [PATCH] Added self hosting key generate command --- .../SelfHost/SelfHostGenerateKeys.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 app/Console/Commands/SelfHost/SelfHostGenerateKeys.php diff --git a/app/Console/Commands/SelfHost/SelfHostGenerateKeys.php b/app/Console/Commands/SelfHost/SelfHostGenerateKeys.php new file mode 100644 index 00000000..cec38ee2 --- /dev/null +++ b/app/Console/Commands/SelfHost/SelfHostGenerateKeys.php @@ -0,0 +1,58 @@ +option('format'); + $key = RSA::createKey((int) $this->option('length')); + + $publicKey = (string) $key->getPublicKey(); + $privateKey = (string) $key; + $appKey = 'base64:'.base64_encode(Encrypter::generateKey(config('app.cipher'))); + + if ($format === 'env') { + $this->line('APP_KEY="'.$appKey.'"'); + $this->line('PASSPORT_PRIVATE_KEY="'.$publicKey.'"'); + $this->line('PASSPORT_PUBLIC_KEY="'.$privateKey.'"'); + } elseif ($format === 'yaml') { + $this->line('APP_KEY: "'.$appKey.'"'); + $this->line("PASSPORT_PRIVATE_KEY: |\n ".Str::replace("\n", "\n ", $privateKey)); + $this->line("PASSPORT_PUBLIC_KEY: |\n ".Str::replace("\n", "\n ", $publicKey)); + } else { + $this->error('Invalid format'); + + return self::FAILURE; + } + + return self::SUCCESS; + } +}