PHP:openssl_seal():不是公钥(pubkeys 的第 1 个成员)

发布于 2025-01-10 09:13:15 字数 1116 浏览 0 评论 0原文

我正在克隆 Laravel 项目的存储库。 我克隆了该存储库并执行 php artisan key:generate ,它正确设置了 .env 中的密钥。但是,当应用程序发出外部 API 请求时,它会失败并显示我检查过的错误

openssl_seal(): not a public key (1th member of pubkeys)

,并且 env('API_KEY') 和 'API_URL' 变量是正确的。

public static function request(string $url, $data = []): Response
{
    //This is where the code fails
    $encrypt_result = self::encrypt($data, env('API_KEY'));

    return Http::asForm()->post(env('API_URL') . $url, [
        'key' => env('API_KEY'),
        'hash' => $encrypt_result['hash'],
        'e_key' => $encrypt_result['key']
    ]);
}

public static function encrypt(array $data, string $public_key): array
{
    //This is where the code fails
    openssl_seal(json_encode($data), $encrypted, $e_keys, [base64_decode($public_key)]);

    return [
        'hash' => base64_encode($encrypted),
        'key' => base64_encode($e_keys[0])
    ];
}

我之前看到过一些问题将此归因于 XAMPP 的错误,并且我在 Windows 上使用 XAMPP,尽管随后将其替换为 Wampserver,但问题仍然存在。

虽然在这个项目上全职使用 Linux 是不可行的,但我稍后会对其进行测试。

有什么简单的事情我可能会忽略吗?

I am cloning a repo of a Laravel project.
I clone the repo and do php artisan key: generate which correctly sets the keys in .env. However when the app makes an external API request, it fails with the error

openssl_seal(): not a public key (1th member of pubkeys)

I have checked and the env('API_KEY') and 'API_URL' variables are correct.

public static function request(string $url, $data = []): Response
{
    //This is where the code fails
    $encrypt_result = self::encrypt($data, env('API_KEY'));

    return Http::asForm()->post(env('API_URL') . $url, [
        'key' => env('API_KEY'),
        'hash' => $encrypt_result['hash'],
        'e_key' => $encrypt_result['key']
    ]);
}

public static function encrypt(array $data, string $public_key): array
{
    //This is where the code fails
    openssl_seal(json_encode($data), $encrypted, $e_keys, [base64_decode($public_key)]);

    return [
        'hash' => base64_encode($encrypted),
        'key' => base64_encode($e_keys[0])
    ];
}

I have previously seen questions that attribute this to an error with XAMPP, and I was using XAMPP on Windows though have subsequently replaced it with Wampserver and the issue persists.

While using Linux on this project fulltime is not viable, I will be testing it later.

Is there anything simple I might be overlooking?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万劫不复 2025-01-17 09:13:15

该问题似乎是 Windows 问题。既然你说它将在 Linux 上运行,我会将应用程序移动到 Linux docker 容器中。您可以通过几个步骤将现有的 Laravel 项目容器化。与 Laravel 风帆。该文档解释得很好: https://laravel.com/docs/8.x/sail

如果您的composer.json中没有Sail,请将其添加到composer require laravel/sail --dev

但如果您熟悉 docker-compose,那么只需使用 docker plain 即可,无需使用 Laravel Sail。

The problem seems to be a Windows problem. Since you said it would run on Linux, I would move the application into a Linux docker container. You can containerize existing Laravel projects in a few steps. With Laravel Sail. The documentation explains it very well: https://laravel.com/docs/8.x/sail.

If there is no Sail in your composer.json, add it to composer require laravel/sail --dev.

But if you are familiar with docker-compose then just use docker plain without Laravel Sail.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文