I am trying to upgrade my phpseclib-based scripts to the latest, which is version 3. (Previously, I was using version 2.) I have run into a number of problems, beginning with the fact that class Crypt_RSA no longer exists. I am compelled to do this because upgrade of MacOS to Tahoe 26.x seems to have broken my remote systems' ability to connect via phpseclib.
I have been looking for documentation that tells me the steps I need to take in order to ugrade my scripts to the new phpseclib version, and having no success. Or even a "Getting Started with phpseclib V3," from which I can determine my own changes, starting from scratch.
For code details, this is where my initial problems lie. The Class Not Found error occurred at the beginning of the following code:
$privateKey = new Crypt_RSA() ;
if ($privateKey->loadKey(file_get_contents($this->privateKeyFile))) {
$this->privateKey = $privateKey ;
} else {
$this->privateKey = null ;
}
So pursuing a new method to do that, I found this answer. So my new code at that section now looks like this:
// added at top of code:
use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Math\BigInteger;
$modulus = 'somevalue'; // From the referenced answer. Probably not what I want, but could not find any better
$exponent = 'ZZZZ'; // Probably not what I want, but ...
$modulus = new BigInteger(base64_decode($modulus), 256);
$exponent = new BigInteger(base64_decode($exponent), 256);
$privateKey = PublicKeyLoader::load([
'n' => $modulus,
'e' => $exponent
]);
if ($privateKey->loadKey(file_get_contents($this->privateKeyFile))) {
$this->privateKey = $privateKey ;
} else {
$this->privateKey = null ;
}
But this leads me to additional problems. First, that I needed to install php-gmp (which I have now done) and now the referenced answer fails with an error about method PublicKeyLoader::load() needing a first parameter string rather than an array.... I am concerned about how deep this rabbit hole goes, Clearly, for this problem, brute force is the wrong approach.
Can anyone point me in the right direction so that I can move forward with the upgrade of phpseclib to V3 from V2?
After some back and forth with the OP it turns out that the issue was that they were using phpseclib v1 vs v2.
In phpseclib v2 you'd instantiate an instance of \phpseclib\Crypt\RSA, however, in phpseclib v1, you'd instance an instance of Crypt_RSA. phpseclib v2 made use of namespaces, which PHP didn't start supporting until PHP 5.3, whereas phpseclib v1, in theory, works on versions of PHP as low as PHP 4.4.
Because the poster was using phpseclib v1 phpseclib2_compat isn't an option - phpseclib2_compat uses phpseclib v3 to emulate phpseclib v2.