Skip to content
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

Error: Ciphertext representative out of range #129

Open
soft17 opened this issue Dec 5, 2022 · 1 comment
Open

Error: Ciphertext representative out of range #129

soft17 opened this issue Dec 5, 2022 · 1 comment

Comments

@soft17
Copy link

soft17 commented Dec 5, 2022

can please someone help me with decripting message error? it throw "Ciphertext representative out of range"

Fatal error:  Uncaught OutOfRangeException: Ciphertext representative out of range in /pgp/vendor/phpseclib/phpseclib/phpseclib/Crypt/RSA/PrivateKey.php:68
Stack trace:
#0 /pgp/vendor/phpseclib/phpseclib/phpseclib/Crypt/RSA/PrivateKey.php(320): phpseclib3\Crypt\RSA\PrivateKey->rsadp()
#1 /pgp/vendor/phpseclib/phpseclib/phpseclib/Crypt/RSA/PrivateKey.php(441): phpseclib3\Crypt\RSA\PrivateKey->rsaes_pkcs1_v1_5_decrypt()
#2 /pgp/lib/openpgp_crypt_rsa.php(218): phpseclib3\Crypt\RSA\PrivateKey->decrypt()
#3 /pgp/lib/openpgp_crypt_rsa.php(200): OpenPGP_Crypt_RSA::try_decrypt_session()

my code:

$keyEncrypted = OpenPGP_Message::parse(OpenPGP::unarmor(file_get_contents(private.asc'), 'PGP PRIVATE KEY BLOCK'));

// try each secret key packet
foreach($keyEncrypted as $p) {
    if(!($p instanceof OpenPGP_SecretKeyPacket)) continue;
    $key = OpenPGP_Crypt_Symmetric::decryptSecretKey('secret', $p);
    $msg = OpenPGP_Message::parse(OpenPGP::unarmor($msgEncrypted, 'PGP MESSAGE'));
    $decryptor = new OpenPGP_Crypt_RSA($key);
    $decrypted = $decryptor->decrypt($msg); // if i call this get that error
}

thanks <3

@soft17
Copy link
Author

soft17 commented Dec 5, 2022

i think its fixed by replace this line:

if(!($p instanceof OpenPGP_SecretKeyPacket)) continue;

by:

if(!(get_class($p) == 'OpenPGP_SecretKeyPacket')) continue;

there was "OpenPGP_SecretSubkeyPacket" what is also instanceof "OpenPGP_SecretKeyPacket", change skipped that subkey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant