singpolyma / openpgp-php

OpenPGP.php is a pure-PHP implementation of the OpenPGP Message Format (RFC 4880).
http://singpolyma.github.io/openpgp-php/
The Unlicense
180 stars 70 forks source link

Displaying message #54

Closed lukaisailovic closed 7 years ago

lukaisailovic commented 7 years ago

Hey, I'm successfully encrypting a message like this:

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

And I'm left with an instance of OpenPGP_Message . How can I display this message to someone now in order to have it decrypted by user?

singpolyma commented 7 years ago

call to_bytes on the message. Use the ASCII armour helpers on the resulting bytes if you want that.

lukaisailovic commented 7 years ago

@singpolyma Hmm looks like I'm doing something wrong, when I try to decrypt it (using windows software) I get no data. This is my code:

$key = OpenPGP_Message::parse(
            OpenPGP::unarmor($pubkey, 'PGP PUBLIC KEY BLOCK')
        );

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

      $armored=  OpenPGP::enarmor($encrypted->to_bytes(),'PGP MESSAGE');
      echo $armored;
singpolyma commented 7 years ago

At a glance, your code looks like the right idea to me. Do you get an error from your decrypt attempt, or just no data?

lukaisailovic commented 7 years ago

Well I'm trying to have some data encrypted for users for decrypt on their computes. When I try to decrypt it I'm just getting No data in gpg4usb and kleopatra could not determine the type. So no idea what is going on here

singpolyma commented 7 years ago

so are you getting errors? Could you screenshot the error?

lukaisailovic commented 7 years ago

Okay, I've used multiple clients now and these are messages I'm getting when trying to decrypt message with each one of them: (every client have my private key imported): pgp4usb - No data error https://image.prntscr.com/image/_e9N6VrJRfirdKqzocIvXQ.png kleopatra - https://image.prntscr.com/image/L2iacnFsRQmRtLPji4PYPg.png

singpolyma commented 7 years ago

Could you also paste the output you tried to feed these programs for decryption?

lukaisailovic commented 7 years ago

Fixed it. It was a spacing problem. When you just echo output it does not create right spacing. You have to put it in something like textarea

OxMarco commented 4 years ago

I'm using the exact same code but can't decrypt it, plus every time I run it a totally different message is generated (the resulting messages have different character sequences).

        $key = OpenPGP_Message::parse(
            OpenPGP::unarmor($pubkey, 'PGP PUBLIC KEY BLOCK')
        );
        $message = 'Hello World';
        $data = new OpenPGP_LiteralDataPacket($message);
        $encrypted = OpenPGP_Crypt_Symmetric::encrypt(
                $key,
                new OpenPGP_Message(array($data))
        );

        $armored = OpenPGP::enarmor($encrypted->to_bytes(),'PGP MESSAGE');
        echo $armored;
singpolyma commented 4 years ago

A different encrypted output every time is expected, since there are usually timestamps etc.

If you get an error trying to decrypt something made with that code, what error do you get?