singpolyma/openpgp-php

Can't decrypt files encrypted with OpenPGP.php

dandys opened this issue · 5 comments

When I try to encrypt some small text, GPG can decrypt this file without problem:

require_once dirname(__FILE__).'/openpgp-php/vendor/autoload.php';

$message = 'Test message';

$key = OpenPGP_Message::parse(
OpenPGP::unarmor(file_get_contents('public.asc'), 'PGP PUBLIC KEY BLOCK')
);

$data = new OpenPGP_LiteralDataPacket($message);
$encrypted = OpenPGP_Crypt_Symmetric::encrypt(
$key,
new OpenPGP_Message(array($data))
);

file_put_contents('output.txt.asc', OpenPGP::enarmor($encrypted->to_bytes(), 'PGP MESSAGE'));

However, when I set $message variable with:

$message = file_get_contents('test.pdf');

or any other bigger text file, GPG (I use KGPG frontend) shows an error with decryption.

What causes an error?

I attach test.pdf file to this issue.
test.pdf

You mean second argument of LiteraDataPacket? Here's the constructor:

function __construct($data=NULL, $opt=array()) {
    parent::__construct();
    $this->data = $data;
    $this->format = isset($opt['format']) ? $opt['format'] : 'b';
    $this->filename = isset($opt['filename']) ? $opt['filename'] : 'data';
    $this->timestamp = isset($opt['timestamp']) ? $opt['timestamp'] : time();
}

So 'b' is the default value of 'format' option.

Sure. If you need any additional informations, let me know.

This appears to be a bug in the enarmor code, it works fine without that.