tab
(Tarab)
December 24, 2013, 4:14pm
1
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?
xkira
(Zelnaga+Xkira)
December 26, 2013, 5:11pm
3
I guess you could include Crypt_RSA explicitly. ie. make sure it’s in your include_path and do a require_once or something.
tab
(Tarab)
December 26, 2013, 6:45pm
4
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?
argent
(Argent Hun)
December 27, 2013, 8:45am
5
Try this extension: yii-phpseclib
tab
(Tarab)
December 28, 2013, 10:09am
6
Thank you Argent! You’ve created a very useful extension
I will try soon this extension
tab
(Tarab)
December 28, 2013, 2:45pm
7
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
argent
(Argent Hun)
December 28, 2013, 3:14pm
8
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).
argent
(Argent Hun)
December 28, 2013, 4:25pm
9
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.
tab
(Tarab)
December 28, 2013, 4:59pm
10
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:
argent
(Argent Hun)
December 28, 2013, 5:05pm
11
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";
tab
(Tarab)
December 28, 2013, 5:29pm
12
This is my output:
test1
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\pear\Crypt\RSA.php on line 232
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\pear\Crypt\RSA\MathLoader.php on line 120
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\pear\Crypt\RSA\Key.php on line 211
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\pear\Crypt\RSA\Key.php on line 301
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\pear\Crypt\RSA\KeyPair.php on line 207
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\pear\Crypt\RSA\KeyPair.php on line 279
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\pear\Crypt\RSA\KeyPair.php on line 294
Strict Standards: Non-static method Crypt_RSA_MathLoader::loadWrapper() should not be called statically, assuming $this from incompatible context in C:\xampp\php\pear\Crypt\RSA.php on line 195
Strict Standards: Non-static method Crypt_RSA_MathLoader::loadWrapper() should not be called statically, assuming $this from incompatible context in C:\xampp\php\pear\Crypt\RSA\MathLoader.php on line 97
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?
argent
(Argent Hun)
December 28, 2013, 6:07pm
13
tab:
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.
tab
(Tarab)
December 29, 2013, 10:26am
14
Great! It perfectly works!
Thank you very much.