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

Cant decrypt on CLI #113

Open
Petah opened this issue Oct 4, 2021 · 1 comment
Open

Cant decrypt on CLI #113

Petah opened this issue Oct 4, 2021 · 1 comment

Comments

@Petah
Copy link

Petah commented Oct 4, 2021

Hi,

When trying to decrypt the output of this lib using gpg cli tool I get this:

$ gpg --decrypt test.enc                                    
gpg: assuming IDEA encrypted data
gpg: [don't know]: indeterminate length for invalid packet type 2
gpg: WARNING: encrypted message has been manipulated!
gpg: [don't know]: invalid packet (ctb=40)

This is the PHP code

$pk = OpenPGP_Message::parse(file_get_contents('public.asc'));
$data = new OpenPGP_LiteralDataPacket("some text\n", ['format' => 'u']);
$encrypted = OpenPGP_Crypt_Symmetric::encrypt([$pk], new OpenPGP_Message([$data]));
echo OpenPGP::enarmor($encrypted->to_bytes(), 'PGP MESSAGE');
@markkimsal
Copy link

The key itself needs to be un-armored and parsed

  $pubkey = './test-public-key.asc';
  $pk = OpenPGP_Message::parse(\OpenPGP::unarmor(file_get_contents($pubkey), 'PGP PUBLIC KEY BLOCK'));
  foreach ($pk->packets as $p) { 
      if (!($p instanceof \OpenPGP_PublicKeyPacket)) { 
          continue;
      } 
      $publickeyPacket = $p;
  }
  $data = new OpenPGP_LiteralDataPacket("some text\n", ['format' => 'u']);
  $encrypted = OpenPGP_Crypt_Symmetric::encrypt([$publickeyPacket], new OpenPGP_Message([$data]));                                                                    
  echo OpenPGP::enarmor($encrypted->to_bytes(), 'PGP 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

2 participants