【问题标题】:PHP Fatal error: Class 'Crypt_RSA' not foundPHP致命错误:找不到类'Crypt_RSA'
【发布时间】:2022-04-09 05:54:01
【问题描述】:

我正在使用 php phpseclib。执行脚本时出现以下错误

 PHP Fatal error:  Class 'Crypt_RSA' not found
 in /home/xxxxx/public_html/index.php on line 5

PHP 脚本

<?php

include('library/php/Net/SSH2.php');

$key = new Crypt_RSA();
$key->setPassword('891600909v');
$key->loadKey(file_get_contents('891600909'));<--This is the pvt key file in home directory in my ubuntu PC-->

$ssh = new Net_SSH2('www.xxxxx.com');
if (!$ssh->login('xxxxx.com', $key)) {
    exit('Login Failed');
}

echo $ssh->read('xxxxx.com@xxxxx.com:~$');
$ssh->write("ls -la\n");
echo $ssh->read('xxxxx.com@xxxxx.com:~$');

?>

我该如何解决这个问题?

【问题讨论】:

    标签: php ubuntu ssh phpseclib


    【解决方案1】:

    您还需要包含 Crypt_RSA 类的 RSA.php 文件。

    将此添加到您的其他包含下方(假设您已下载此文件):

    include('library/php/Crypt/RSA.php');
    

    【讨论】:

    • 现在说 require_once(Math/BigInteger.php): failed to open stream: No such file or directory in /home/xxxxx/public_html/library/php/Crypt/RSA.php on line 465
    • 确保您已将整个软件包下载到那里,并且目录结构与 ZIP 保持一致。
    • 我应该将什么文件包含到 $key->loadKey(file_get_contents('891600909')); ???
    【解决方案2】:

    除了 Ryan Kempt 所说的之外,请确保您的 include_path 设置正确。例如。

    <?php
    set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
    
    include('Net/SSH2.php');
    

    【讨论】:

      【解决方案3】:

      您可以使用 pear 安装 phpseclib 或从网站获取它们

      http://phpseclib.sourceforge.net/pear.htm

      手动下载您想要的每个类并将它们包含在您的主项目中。

      【讨论】:

        【解决方案4】:

        在当前版本的 phpseclib 中,Crypt_RSA 类不再存在。 您可以这样创建它:

        $rsa = \phpseclib3\Crypt\RSA::load("...");
        

        $rsa = \phpseclib3\Crypt\RSA::createKey();
        

        【讨论】:

          猜你喜欢
          • 2015-03-20
          • 2022-01-02
          • 2013-09-27
          • 2013-08-16
          • 2016-08-21
          • 2014-05-08
          • 2012-08-02
          • 2012-01-02
          • 2014-01-02
          相关资源
          最近更新 更多