New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot instantiate abstract class phpseclib3\Crypt\RSA #1937
Comments
You're using the phpseclib2 syntax. For phpseclib3 you'd need to do something more like this: <?php
namespace Modules\Smime;
use phpseclib3\Crypt\RSA;
use phpseclib3\File\X509;
class SmimeDecrypter
{
public function decrypt($encryptedMessage, $privateKeyPath, $certificatePath, $outputPath)
{
// Load the private key
$rsa = PublicKeyLoader::load(file_get_contents($privateKeyPath));
// You can continue loading and using the X509 certificate as before
$x509 = new X509();
$cert = $x509->loadX509(file_get_contents($certificatePath));
// Decrypt the S/MIME message using the private key
$decryptedMessage = $rsa->decrypt($encryptedMessage);
if ($decryptedMessage !== false) {
// Save the decrypted message to the specified output path
file_put_contents($outputPath, $decryptedMessage);
return true;
} else {
return false;
}
}
} |
Note that phpseclib3 changed some of the default hashes (sha256 is now the default vs sha1, which phpseclib1 used as the default) so you might need to tweak that as well. http://phpseclib.com/docs/why#phpseclib-30-vs-phspeclib-10--20 elaborates. Alternatively, you could use https://github.com/phpseclib/phpseclib2_compat to use phpseclib2 style code with phpseclib3. |
I have Implemented using phpseclib version 2 but when execution this controller there is error as I attach image below :
here the error when execution controller above |
|
Maybe your ciphertext doesn't use any padding. Maybe the key that you're using isn't the right one. Could be any number of things. At this point, without the ciphertext and key I'm not going to be able to provide a ton of insight. And even with those things, if the key is wrong, there's not a whole heck of a lot imma be able to do. Like I'll be able to tell you if the ciphertext doesn't use any padding at all (assuming the key is correct), but that's about it... |
I have code below for decrypt function :
but when I execute there is error Cannot instantiate abstract class phpseclib3\Crypt\RSA, is there any suggestion for the right code above for succeded decryption
The text was updated successfully, but these errors were encountered: