gpt4 book ai didi

php - 将 phpseclib 集成到 Laravel 5

转载 作者:可可西里 更新时间:2023-11-01 00:00:10 26 4
gpt4 key购买 nike

我目前正在将我的项目从 Laravel 4 迁移到 Laravel 5,我仍然是 Laravel 和 OOP 的新手用户,但到目前为止一切都很顺利。

但是,在我的 L4 项目中,我使用 phpseclib 生成 SSH key ,我通过以下方式导入了这些 key :

MyController.php

...
include('../app/libs/phpseclib0.3.10/Crypt/RSA.php');
$rsa = new Crypt_RSA();
...

这似乎不再有效了:

syntax error, unexpected 'if' (T_IF), expecting identifier (T_STRING) 

.../app/libs/phpseclib0.3.10/Crypt/RSA.php

/**
* Include Crypt_Random
*/
// the class_exists() will only be called if the crypt_random_string function hasn't been defined and
// will trigger a call to __autoload() if you're wanting to auto-load classes
// call function_exists() a second time to stop the include_once from being called outside
// of the auto loader
if (!function_exists('crypt_random_string')) {
include_once 'Random.php';
}

我知道有一个 phpseclib 包: https://packagist.org/packages/phpseclib/phpseclib

而且我也知道如何在我的 L5 项目中安装它。

但是,我不知道如何在我的 Laravel 5 项目中使用 phpseclib 包。

所以,在我的 L5 项目中安装了 phpseclib 包之后,如何创建我的 SSH key 类似于这样:

$rsa = new Crypt_RSA();

最佳答案

返工this other answer并查看 vendor/phpseclib/文件夹,我设法让它使用这种语法:

use phpseclib\Crypt\RSA;
...
...
$rsa = new RSA();
$rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH);
extract($rsa->createKey());
echo "$publickey\r\n\r\n$privatekey";

至少,它适用于 phpseclib 版本 ^2.0

关于php - 将 phpseclib 集成到 Laravel 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28739971/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com