我有一个
TokenParser
类,看起来像这样:
https://github.com/cgauge/laravel-cognito-provider/blob/master/src/TokenParser.php
我的应用程序与 L8 (php 7.4) 完美运行,但在升级到 L9 LTS (php 8.2) 后,
loadAndVerifyWithKeySet()
函数执行了大约 19 秒。经过一些挖掘后,有一个签名算法验证功能导致缓慢:
// file: jwt-signature-algorithm-rsa/RSAPKCS1.php
public function verify(JWK $key, string $input, string $signature): bool
{
$this->checkKey($key);
$pub = RSAKey::createFromJWK($key->toPublic()); // Causes slowness
return openssl_verify($input, $signature, $pub->toPEM(), $this->getAlgorithm()) === 1;
}
有人可以帮我解决这个问题吗?什么可能导致解析令牌缓慢?
Florent Morselli 帮我解决了这个问题:
“当基于 RSA 的密码操作缓慢时,这意味着它使用 PHP 类而不是 GMP 或 BCMATH 扩展。”
我在 PHP 8.2 (Ubuntu) 上安装了 GMP 扩展