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?
phpseclib2_compatwhich can be found here. This package allows your existing phpseclib 2 code to internally utilize phpseclib 3, providing enhanced features like support for ECDSA, DSA, Ed25519, and Ed449 keys. installation.$privateKey = new Crypt_RSA()makes me think you're using phpseclib v1. phpseclib v2 is namespaced so in phpseclib v2 you'd be doing$privateKey = new \phpseclib\Crypt\RSA().