diff --git a/composer.json b/composer.json index 4eb1089da..0726c28c7 100644 --- a/composer.json +++ b/composer.json @@ -26,10 +26,10 @@ "illuminate/encryption": "^8.2", "illuminate/http": "^8.2", "illuminate/support": "^8.2", - "league/oauth2-server": "^8.2", "lcobucci/jwt": "^3.4|^4.0", + "league/oauth2-server": "^8.2", "nyholm/psr7": "^1.3", - "phpseclib/phpseclib": "^3.0", + "phpseclib/phpseclib": "^2.0|^3.0", "symfony/psr-http-message-bridge": "^2.0" }, "require-dev": { diff --git a/src/Console/KeysCommand.php b/src/Console/KeysCommand.php index b0851acec..36ff6e6c6 100644 --- a/src/Console/KeysCommand.php +++ b/src/Console/KeysCommand.php @@ -3,7 +3,9 @@ namespace Laravel\Passport\Console; use Illuminate\Console\Command; +use Illuminate\Support\Arr; use Laravel\Passport\Passport; +use phpseclib\Crypt\RSA as LegacyRSA; use phpseclib3\Crypt\RSA; class KeysCommand extends Command @@ -39,10 +41,17 @@ public function handle() if ((file_exists($publicKey) || file_exists($privateKey)) && ! $this->option('force')) { $this->error('Encryption keys already exist. Use the --force option to overwrite them.'); } else { - $key = RSA::createKey($this->input ? (int) $this->option('length') : 4096); + if (class_exists(LegacyRSA::class)) { + $keys = (new LegacyRSA)->createKey($this->input ? (int) $this->option('length') : 4096); - file_put_contents($publicKey, (string) $key->getPublicKey()); - file_put_contents($privateKey, (string) $key); + file_put_contents($publicKey, Arr::get($keys, 'publickey')); + file_put_contents($privateKey, Arr::get($keys, 'privatekey')); + } else { + $key = RSA::createKey($this->input ? (int) $this->option('length') : 4096); + + file_put_contents($publicKey, (string) $key->getPublicKey()); + file_put_contents($privateKey, (string) $key); + } $this->info('Encryption keys generated successfully.'); }