简体   繁体   English

将phpseclib整合到Laravel 5中

[英]Integrate phpseclib into Laravel 5

i am currently migrating my Project from Laravel 4 to Laravel 5, i am still a novice user of Laravel and OOP as well but everything went smoothly so far. 我目前正将我的项目从Laravel 4迁移到Laravel 5,我仍然是Laravel和OOP的新手用户,但到目前为止一切顺利。

However, in my L4 project I use the phpseclib for generating SSH keys which I imported in the following way: 但是,在我的L4项目中,我使用phpseclib生成SSH密钥,我通过以下方式导入:

MyController.php MyController.php

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

which does not seems to work anymore: 这似乎不再起作用了:

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

.../app/libs/phpseclib0.3.10/Crypt/RSA.php ... /应用/库/ phpseclib0.3.10 /地穴/ 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';
}

I know that there is a phpseclib package: https://packagist.org/packages/phpseclib/phpseclib 我知道有一个phpseclib包: https ://packagist.org/packages/phpseclib/phpseclib

and I also know how to Install it in my L5 Project. 我也知道如何在我的L5项目中安装它。

However, I dont know how to use the phpseclib package in my Laravel 5 project after I installed it. 但是,我安装后,我不知道如何在我的Laravel 5项目中使用phpseclib软件包。

So, after I installed the phpseclib package in my L5 Project, how to create my SSH Key similar to this: 因此,在我的L5项目中安装了phpseclib软件包之后,如何创建类似于此的SSH密钥:

$rsa = new Crypt_RSA();

Reworking this other answer and getting a look into the vendor/phpseclib/ folder, I've managed to get it working with this syntax: 重新处理这个其他答案并查看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";

At least, it works on phpseclib version ^2.0 至少,它适用于phpseclib版本^ 2.0

PHPSec确实使用了作曲家,你应该能够让composer require "phpseclib/phpseclib=~0.3.10"并让它可用(自动加载)。

$rsa = new \Crypt_RSA();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM