Vendor/phpseclib - Include(Crypt_Rsa.php): Failed To Open Stream

Hi,

I wish to include phpseclib in my Yii project.

I tried to follow this article/guide but it doesn’t works.

My versions are:

Yii - 1.1.last

phpseclib - 0.3.5

When I try to run the simple function I wrote




private function decrypt($msg)

{

	$rsa = new Crypt_RSA();

	// others files....

}



the system show this errors:

Where is the error?

Any ideas?

I guess you could include Crypt_RSA explicitly. ie. make sure it’s in your include_path and do a require_once or something.

After a long time spend to solve my issues I know the correct vendor path (in my case) was vendor and not vendors.

So, I have followed all steps of this tutorial but I have this issue: include(Math_BigInteger.php): failed to open stream: No such file or directory.

So, I think the problem is at line 464 of Crypt_RSA.php: if I remove


if (!class_exists('Math_BigInteger')) {

It works very fine. Why?

Try this extension: yii-phpseclib

Thank you Argent! You’ve created a very useful extension ;)

I will try soon this extension

Hi Argent,

I tried your extension but RSA encryption seems doesn’t works.

If I write




echo "test1";


$keys = Yii::app()->phpseclib->createRSA()->createKey();

print_r($keys);


echo "test2";



the system only print "test1" as if there are some problems with a new instance of RSA

When I tested I got same result.

My problem was the execution time (PHP Fatal error: Maximum execution time of 30 seconds exceeded in /path/to/phpseclib/classes/Math/BigInteger.php on line 1700).

But I think it is not an extension bug because I got same result if I try without Yii… try to increase the limit, e.g.: set_time_limit(120);

(the speed is strange: on my localhost (mamp) the key generate with php 5.2.17 is about 0.03-0.09sec, with php 5.4.19 it is 7-42sec - I will try to find out what causes it).

I’m back… so… check your openssl extension in the phpinfo().

On my machine the openssl is enabled under php 5.4.19, but the phpseclib is ignore it because the openssl Library and Header versions are different:




openssl


OpenSSL support	enabled

OpenSSL Library Version	OpenSSL 0.9.8y 5 Feb 2013

OpenSSL Header Version	OpenSSL 0.9.8r 8 Feb 2011



Here is the code: click here

Try to install/enable the openssl extension.

If already enabled but header/library versions are different try this hack:




echo "test1";

Yii::app()->phpseclib->preload("Crypt_RSA");

if(extension_loaded('openssl') && file_exists(CRYPT_RSA_OPENSSL_CONFIG)) {

    define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_OPENSSL);

}

$keys = Yii::app()->phpseclib->createRSA()->createKey();

print_r($keys);

echo "test2";



without openssl support the phpseclib is use BigInteger class and this is too slow.

If this is not the problem, then please check your php error log.

Hi Argent,

I check my phpinfo() and my XAMPP has

So, my library and header are the same. Where is the problem?

I also tried to put




echo "test1";

Yii::app()->phpseclib->preload("Crypt_RSA");

if(extension_loaded('openssl') && file_exists(CRYPT_RSA_OPENSSL_CONFIG)) {

    define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_OPENSSL);

}

$keys = Yii::app()->phpseclib->createRSA()->createKey();

print_r($keys);

echo "test2";



I have this error:

What is the output of this code?




error_reporting(E_ALL);

ini_set('display_errors', 1);

echo "test1";

$keys = Yii::app()->phpseclib->createRSA()->createKey();

print_r($keys);

echo "test2";



This is my output:

I think is a problem of path setting because /Crypt/RSA.php is not in C:\xampp\php\pear but in [color="#FF0000"]C:\xampp\htdocs\yii\app\protected\extensions\phpseclib

[/color]

Another thing: I also tried to test phpseclib RSA out of Yii framework (in localhost and on my hosting) and everything works!

Can be a problem of path?

Yes, I’m sorry - It was my fault.

Please download the new 0.2 version from the here: click here, replace the PhpSecLib.php and try again.

Great! It perfectly works!

Thank you very much.