简体   繁体   中英

RSA decryption in error in php using phpseclib

Hi I am trying to decrypt the message using phpseclib. The error i am getting is

"Class 'phpseclib\Crypt\Base' not found"

I am using decrypt code from below url:

http://www.sitepoint.com/encrypt-large-messages-asymmetric-keys-phpseclib/

It looks like the version you're using is using namespaces. Which means you're using either phpseclib 2.0 or the version in the master branch on github. What you'll need to do, in this case, is to use a PSR-4 compliant autoloader.

Best approach would be just use Composer to install phpseclib as a dependency. eg. do composer require phpseclib/phpseclib:~2.0 via the CLI in your projects directory and then do this:

<?php 
require __DIR__ . '/vendor/autoload.php' 

use phpseclib\Crypt\RSA; 

$rsa = new RSA();

But if you don't want to do that you should also be able to do this:

<?php
include('autoload.php'); // https://raw.githubusercontent.com/composer/composer/master/src/Composer/Autoload/ClassLoader.php 

$loader = new \Composer\Autoload\ClassLoader(); 
$loader->addPsr4('phpseclib\\', __DIR__.'/path/to/phpseclib'); 
$loader->register();

use \phpseclib\Crypt\RSA;

$rsa = new RSA();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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