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

Not an asymmetrically encrypted message when trying to decrypt #115

Open
weisinlakd opened this issue Oct 28, 2021 · 0 comments
Open

Not an asymmetrically encrypted message when trying to decrypt #115

weisinlakd opened this issue Oct 28, 2021 · 0 comments

Comments

@weisinlakd
Copy link

Hi. I'm not sure what I'm doing wrong here since its my first time messing with PGP keys.
From what I understand this should work since its pretty much the example, with an already encrypted message as the only difference.

Are the keys wrong? I sometimes see an error of Invalid ASCII armor, missing CRC but its not consistent.

By messing with indentation on the message i get a Call to a member function setEncryptionMode() on null when trying to decrypt.

Any pointers would be appreciated, since im completly lost.

Thank you!

$private = "-----BEGIN PGP PRIVATE KEY BLOCK-----

xYYEYXqr4BYJKwYBBAHaRw8BAQdAEZ6RLSIVivTBICZbkoZmqcKVgsS6oOSh
EzrSTg0MTpH+CQMIMamV5Xlo0OXg3PnIKnPM/Kjb8C+FsbXUTqCQ/Dv072W4
OwQTZl5EbAr7AGrR3/ndEECThjaVs0mUtDo+ajinxgzKw1oAyjOVsi4CBVIl
gc0zTHVjaWFubyBMdWR1ZcOxYSA8bHVjaWFuby5sdWR1ZW5hQGNpbnRlbGlu
ay5jb20uYXI+wowEEBYKAB0FAmF6q+AECwkHCAMVCAoEFgACAQIZAQIbAwIe
AQAhCRBwFh99dmUwvhYhBNOiVaHniQEqnR2Jp3AWH312ZTC+IsEBAPYjSO9H
MuiSxFwDUXfa/w1Yc7Qef3LX153+GJoI3Fu9AP9ry+jFrCZz7EPnT94SZpwS
UCy9z3QwkOZwXIOynrD1DceLBGF6q+ASCisGAQQBl1UBBQEBB0BylLdOa5Qs
9UiEO3i2xiFiiuqdqSJLK+yP5el+uodzBAMBCAf+CQMIbpPSBbFx76/gKtjF
hzN65JYejHDU3GF5t88Lap0PlCUOrwGug/L4pMEwnM6dZf4Er9cQtPfulGgl
c39GuJR5qOr0xvLnkxTFkNo9AugbJsJ4BBgWCAAJBQJheqvgAhsMACEJEHAW
H312ZTC+FiEE06JVoeeJASqdHYmncBYffXZlML68eAEA4SKcHBwYC+jgfsCP
3ofjRkxPJhMzUaBOvTUAPL6sMmwBAKrVI8lD3vDFfVk4t57lwR9p/vMAk6Wk
ud8J2hIg8bcF
=okZy
-----END PGP PRIVATE KEY BLOCK-----";




$public = "-----BEGIN PGP PUBLIC KEY BLOCK-----

xjMEYXqr4BYJKwYBBAHaRw8BAQdAEZ6RLSIVivTBICZbkoZmqcKVgsS6oOSh
EzrSTg0MTpHNM0x1Y2lhbm8gTHVkdWXDsWEgPGx1Y2lhbm8ubHVkdWVuYUBj
aW50ZWxpbmsuY29tLmFyPsKMBBAWCgAdBQJheqvgBAsJBwgDFQgKBBYAAgEC
GQECGwMCHgEAIQkQcBYffXZlML4WIQTTolWh54kBKp0diadwFh99dmUwviLB
AQD2I0jvRzLoksRcA1F32v8NWHO0Hn9y19ed/hiaCNxbvQD/a8voxawmc+xD
50/eEmacElAsvc90MJDmcFyDsp6w9Q3OOARheqvgEgorBgEEAZdVAQUBAQdA
cpS3TmuULPVIhDt4tsYhYorqnakiSyvsj+XpfrqHcwQDAQgHwngEGBYIAAkF
AmF6q+ACGwwAIQkQcBYffXZlML4WIQTTolWh54kBKp0diadwFh99dmUwvrx4
AQDhIpwcHBgL6OB+wI/eh+NGTE8mEzNRoE69NQA8vqwybAEAqtUjyUPe8MV9
WTi3nuXBH2n+8wCTpaS53wnaEiDxtwU=
=/EX0
-----END PGP PUBLIC KEY BLOCK-----";


$msg= "-----BEGIN PGP MESSAGE-----

        wV4D0hwVDes0eQYSAQdAhOxbhuRCgx0qssQyk5ef32k4uJXxgfjnIEDyXYYt
        GVIwWcZDH+c56CuSxV92ojpqbbW9PvWXC3QOxbGkvrfqWqdtd7g4UeptE2R5
        1v/LmD7c0jkBctfVOpGUoE14T44ypxzd5IL71TrkDR7LNNs08vabVy4hArv3
        HEaXGebJCjLEV1KvqBI70p/uixo=
        =ESj7
        -----END PGP MESSAGE-----";

$decrypted=false;
$keyEncrypted = OpenPGP_Message::parse(
            OpenPGP::unarmor($private, 'PGP PRIVATE KEY BLOCK')
);  

        var_dump($keyEncrypted);


        // $msg = OpenPGP::unarmor($msg, 'PGP MESSAGE');

        var_dump($msg);

        try {
            $msg = OpenPGP_Message::parse($msg);    
        } catch (\Throwable $th) {
            var_dump($th); // if I use unarmor -> Unsupported AsymmetricSessionKeyPacket version: 62
        }


        foreach($keyEncrypted as $p) {
            if(!($p instanceof OpenPGP_SecretKeyPacket)) continue;   
            $key = new OpenPGP_SecretKeyPacket($p->key);
            $decryptor = new OpenPGP_Crypt_RSA($key);            
            try {
                $decrypted = $decryptor->decrypt($msg);    //<-- it does not return     
            } catch (\Throwable $th) {
                var_dump($th); // Uncaught Exception: Not an asymmetrically encrypted message
            }
        }        
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