|
3 | 3 | namespace Laravel\Passport\Console; |
4 | 4 |
|
5 | 5 | use Illuminate\Console\Command; |
| 6 | +use Illuminate\Support\Arr; |
6 | 7 | use Laravel\Passport\Passport; |
| 8 | +use phpseclib\Crypt\RSA as LegacyRSA; |
7 | 9 | use phpseclib3\Crypt\RSA; |
8 | 10 |
|
9 | 11 | class KeysCommand extends Command |
@@ -39,10 +41,17 @@ public function handle() |
39 | 41 | if ((file_exists($publicKey) || file_exists($privateKey)) && ! $this->option('force')) { |
40 | 42 | $this->error('Encryption keys already exist. Use the --force option to overwrite them.'); |
41 | 43 | } else { |
42 | | - $key = RSA::createKey($this->input ? (int) $this->option('length') : 4096); |
| 44 | + if (class_exists(LegacyRSA::class)) { |
| 45 | + $keys = (new LegacyRSA)->createKey($this->input ? (int) $this->option('length') : 4096); |
43 | 46 |
|
44 | | - file_put_contents($publicKey, (string) $key->getPublicKey()); |
45 | | - file_put_contents($privateKey, (string) $key); |
| 47 | + file_put_contents($publicKey, Arr::get($keys, 'publickey')); |
| 48 | + file_put_contents($privateKey, Arr::get($keys, 'privatekey')); |
| 49 | + } else { |
| 50 | + $key = RSA::createKey($this->input ? (int) $this->option('length') : 4096); |
| 51 | + |
| 52 | + file_put_contents($publicKey, (string) $key->getPublicKey()); |
| 53 | + file_put_contents($privateKey, (string) $key); |
| 54 | + } |
46 | 55 |
|
47 | 56 | $this->info('Encryption keys generated successfully.'); |
48 | 57 | } |
|
0 commit comments