首页 > 解决方案 > PhpStorm 致命错误:找不到类“Crypt_RSA”(phpseclib)

问题描述

我正在尝试将 phpseclib 添加为 PhpStorm 中的外部库。

我从 GitHub 下载了 phpseclib,提取了文件并在此处添加了 phpseclib Settings | Languages & Frameworks | PHP | Include Path:.

之后$phpsec = new Crypt_RSA();运行,但给了我这个错误:

致命错误:找不到类“Crypt_RSA”`

之后我尝试了这些行:

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
include('Net/SSH2.php');
include("Crypt/RSA.php");

给我这些错误:

Warning: include(Net/SSH2.php): failed to open stream: No such file or directory
Warning: include(): Failed opening 'Net/SSH2.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear:phpseclib')
Warning: include(Crypt/RSA.php): failed to open stream: No such file or directory
Warning: include(): Failed opening 'Crypt/RSA.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear:phpseclib') 
Fatal error: Class 'Crypt_RSA' not found

也试过这个:

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

给出了同样的错误。

添加phpseclib库并使用它的真正方法是什么。

我的主要目的是使用 sha256 进行 RSA OAEP 公共加密。

标签: phpphpstormphpseclib

解决方案


未能打开 'Crypt/RSA.php' 以包含 (include_path='.:/usr/share/php:/usr/share/pear:phpseclib')

似乎YoursPATH_SEPARATOR不是:. /改变:

set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');

set_include_path(get_include_path() .'/phpseclib'); 或将 Your 设置PATH_SEPARATOR/.


推荐阅读