Skip to content

Error: Ciphertext representative out of range #129

Open

Description

@soft17

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

Activity

  1. soft17 commented on Dec 5, 2022

    @soft17
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions