phplaravelphpseclib

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.

However, in my L4 project I use the phpseclib for generating SSH keys which I imported in the following way:

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

/**
* 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

and I also know how to Install it in my L5 Project.

However, I dont know how to use the phpseclib package in my Laravel 5 project after I installed it.

So, after I installed the phpseclib package in my L5 Project, how to create my SSH Key similar to this:

$rsa = new Crypt_RSA();

Solution

  • PHPSec does use composer, you should be able to just composer require "phpseclib/phpseclib=~0.3.10" and have it available (autoloaded).

    $rsa = new \Crypt_RSA();