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
179 stars 69 forks source link

encrypt and sign #134

Open moszsiame opened 1 year ago

moszsiame commented 1 year ago

i'm trying to encrypt and sign from sample code

decrypt fine but verify fail.

my code `$config = $allConf[1]; $publicKeyPath = $config->publicKeyPath; $privateKeyPath = $config->privateKeyPath; $privateKeyPassphrase = $config->privateKeyPassphrase;

$recipientPublicKey = \OpenPGP_Message::parse(\OpenPGP::unarmor(file_get_contents($publicKeyPath), 'PGP PUBLIC KEY BLOCK')); $encryptedPrivateKey = \OpenPGP_Message::parse(\OpenPGP::unarmor(file_get_contents($privateKeyPath), 'PGP PRIVATE KEY BLOCK'));

$key = OpenPGP_Crypt_Symmetric::decryptSecretKey($privateKeyPassphrase, $encryptedPrivateKey[0]);

$signer = new OpenPGP_Crypt_RSA($key); $data = new OpenPGP_LiteralDataPacket("TEST TEXT"); $signed = $signer->sign($data);

//$compressed = new OpenPGP_CompressedDataPacket($signed);

//var_dump(new OpenPGP_Message([$compressed])); exit;

$encrypted = OpenPGP_Crypt_Symmetric::encrypt([$recipientPublicKey, $key], $signed);

var_dump(OpenPGP::enarmor($encrypted->to_bytes(), 'PGP MESSAGE'));`

moszsiame commented 1 year ago

this is command code in OPENPGP

gpg --pinentry-mode=loopback --passphrase "passphrase " --encrypt --sign -u "user_website_sign" --armor -r "user_website" "./test_file.txt"