Skip to content

Cannot decrypt messages encoded with GPG #133

@bouboot82

Description

@bouboot82

Hi,

Every time I try to run the decryption algorithm on messages encoded with gpg (the key pairs have been generated in gpg as well), I get the following errors :

Severity: Warning

Message: Undefined array key "e"

Filename: lib/openpgp_crypt_rsa.php

Line Number: 250

Backtrace:

File: /OpenPGP-PHP/lib/openpgp_crypt_rsa.php
Line: 250
Function: _error_handler

...

And

A PHP Error was encountered
Severity: Warning

Message: Undefined array key "d"

Filename: lib/openpgp_crypt_rsa.php

Line Number: 251

Backtrace:

File: OpenPGP-PHP/lib/openpgp_crypt_rsa.php
Line: 251
Function: _error_handler

The first and the second errors are triggered when using the armored version of the key and the message.
The second one only is triggered when using the unarmored versions.

The code used for the ASCII version is :

        $keyEncrypted = OpenPGP_Message::parse(OpenPGP::unarmor(file_get_contents(dirname(__FILE__) . '/test.key'), 'PGP PRIVATE KEY BLOCK'));
        foreach($keyEncrypted as $p) {
	        if(!($p instanceof OpenPGP_SecretKeyPacket)) continue;

	        $key = OpenPGP_Crypt_Symmetric::decryptSecretKey('Passphrase', $p);

	        $msg = OpenPGP_Message::parse(OpenPGP::unarmor(file_get_contents(dirname(__FILE__) . '/testArmored.txt'), 'PGP MESSAGE'));

	        $decryptor = new OpenPGP_Crypt_RSA($key);
	        $decrypted = $decryptor->decrypt($msg);
        }

For the unarmored version

        $key = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/test.gpg'));
        $decryptor = new OpenPGP_Crypt_RSA($key);
        $decrypted = $decryptor->decrypt(file_get_contents(dirname(__FILE__) . '/test.asc'));  

The files used for the test are attached.

Thanks in advance
Archive.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions