Skip to content

Commit db454a8

Browse files
committed
phpseclib may now be 2.0 or 3.0 version
1 parent 18c962d commit db454a8

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"google/protobuf": "~3.15.8",
1818
"grpc/grpc": "^1.35",
1919
"lcobucci/jwt": "^3.4",
20-
"phpseclib/phpseclib": "^3.0",
20+
"phpseclib/phpseclib": "^2.0|^3.0",
2121
"psr/log": "~1.0"
2222
},
2323
"autoload": {

src/Jwt/Signer/Sha256.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Lcobucci\JWT\Signer\Key as SignerKey;
66
use Lcobucci\JWT\Signer\Rsa as SignerRsa;
77

8+
use phpseclib\Crypt\RSA as LegacyRSA;
89
use phpseclib3\Crypt\RSA;
910
use phpseclib3\Crypt\PublicKeyLoader;
1011

@@ -17,13 +18,25 @@ class Sha256 extends SignerRsa
1718
*/
1819
public function createHash($payload, SignerKey $key)
1920
{
20-
$private = PublicKeyLoader::load($key->getContent());
21-
22-
$signature = $private
23-
->withPadding(RSA::SIGNATURE_PSS)
24-
->sign($payload);
25-
26-
return $signature;
21+
$keyContent = $key->getContent();
22+
23+
if (class_exists(LegacyRSA::class))
24+
{
25+
$rsa = new LegacyRSA;
26+
$rsa->loadKey($keyContent);
27+
$rsa->setHash('sha256');
28+
$rsa->setMGFHash('sha256');
29+
$rsa->setSignatureMode(LegacyRSA::SIGNATURE_PSS);
30+
31+
return $rsa->sign($payload);
32+
}
33+
else
34+
{
35+
$rsa = PublicKeyLoader::load($keyContent);
36+
$rsa->withPadding(RSA::SIGNATURE_PSS);
37+
38+
return $rsa->sign($payload);
39+
}
2740
}
2841

2942
/**

0 commit comments

Comments
 (0)