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; + } +}