Skip to content

Commit d429a98

Browse files
authored
[10.x] Backport phpseclib v2 (#1418)
* Backport support for phpseclib v2 * Apply fixes from StyleCI (#1417)
1 parent 2ed0190 commit d429a98

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
"illuminate/encryption": "^8.2",
2727
"illuminate/http": "^8.2",
2828
"illuminate/support": "^8.2",
29-
"league/oauth2-server": "^8.2",
3029
"lcobucci/jwt": "^3.4|^4.0",
30+
"league/oauth2-server": "^8.2",
3131
"nyholm/psr7": "^1.3",
32-
"phpseclib/phpseclib": "^3.0",
32+
"phpseclib/phpseclib": "^2.0|^3.0",
3333
"symfony/psr-http-message-bridge": "^2.0"
3434
},
3535
"require-dev": {

src/Console/KeysCommand.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Laravel\Passport\Console;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Support\Arr;
67
use Laravel\Passport\Passport;
8+
use phpseclib\Crypt\RSA as LegacyRSA;
79
use phpseclib3\Crypt\RSA;
810

911
class KeysCommand extends Command
@@ -39,10 +41,17 @@ public function handle()
3941
if ((file_exists($publicKey) || file_exists($privateKey)) && ! $this->option('force')) {
4042
$this->error('Encryption keys already exist. Use the --force option to overwrite them.');
4143
} 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);
4346

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

4756
$this->info('Encryption keys generated successfully.');
4857
}

0 commit comments

Comments
 (0)