将phpseclib集成到Laravel 5中


Integrate phpseclib into Laravel 5

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

然而,在我的L4项目中,我使用phpseclib生成SSH密钥,我通过以下方式导入了这些密钥:

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项目中安装它。

然而,在我安装了phpseclib包之后,我不知道如何在我的Laravel 5项目中使用它

因此,在我的L5项目中安装了phpseclib包之后,如何创建类似于以下内容的SSH密钥:

$rsa = new Crypt_RSA();

重新处理另一个答案,并查看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

PHPSec确实使用composer,您应该只能使用composer require "phpseclib/phpseclib=~0.3.10"并使其可用(自动加载)。

$rsa = new 'Crypt_RSA();