Closed siva-fstack closed 3 years ago
Check the decryption example at: https://github.com/singpolyma/openpgp-php/blob/master/examples/deASCIIdeCrypt.php#L17
You need to iterate through the private key packets until you find a OpenPGP_SecretKeyPacket
. That may be encrypted with a passphrase that you need to decrypt first.
You pass the decrypted OpenPGP_SecretKeyPacket
to OpenPGP_Crypt_RSA()
rather than the entire private key. Then use that $decryptor
to decrypt your message.
Hi,
I need help for below code, i am using pgp public/private keys for encryption and decryption after decrypt nothing has returned.
My code:
`$publickey = '-----BEGIN PGP PUBLIC KEY BLOCK----- Version: BCPG v1.64
mQENBF3OXnsDCADInJcfC0JchkD6MsGlPYkywLX4IsKPtcG7YKNR7+55qdV9NDad jDll5FTGKwPbQxzKL5N/Um4T21xwN6quZu9x3a9W8gfiC75IkGpcE90pUEZ0qE9b rGe2ipc80rCWeji0FEjP0CfDTXGZGe4Knh5pAQBvgDdFSaDFd1M3NRp8cpTCUXrv Jt005G4bOUf3ZMAqcoRsGsK1GvjCiSsNdwKrXRg1Yx93kg+vqAdVIiDEjsX5WHVp WR9utrhbNLVm9TfXIXghn2Z+27ftfs7PxBkghLJeg0/ubgxXO05rN8hMjU8yV/wv R5gOUiYiVcm+v5z+qBd77ouZu1gxIEPAqYFFABEBAAG0FnRlc3QuY2xpZW50QG5j cy5jb20uc2eJAS4EEwMCABgFAl3OXnwCGwMECwkIBwYVCAIJCgsCHgEACgkQUjCb yrkqiWK/Ggf7BqmsWBqQ7HmhGtJnC8RVsiCW1gT3x7NfYOH6HYWioAAm35UUsLLz JkfA+SRog/z0ZiYKcWe0uhH9XcRMuJNxeKgUpT5KCqmzLM50GWLuYOqEvfLSXWjF DcWRoAnmBOsv9kG4FMtTyEtZWMgT0GgiDCWX/trgAWCwlQY15QCwkLqQfep4M8OV HY165i0THfhOSTnzVB+E1FydDE5XoT1qFmsBTM739pjWjW4zKNpOgJ8CRKu8voge Dyu0gN3eBilwoZn5ptz5KgfWSEMUXfrsUQpr9QcLmUeP4QovKxjO7hmooGrC7nr6 XPpwutbaJkWmBzRj7IoiuCS0yj5wD8362LkBDQRdzl58AggAs213+w/vTn8LlzJ5 Ngw24OwxlaO9qyb8SFzXNVP6LCx7OeurK5olnWbpz9C4WJwhNG48/f2rdzXx/WBX ycGdlf2lL+QQgQYWifrxd9Y2DllyjtlQ//9+mG2i0t5Tt5kqvmEocJqtEbiHlD+9 hcyPVQOa3jX7+TttozfaeaAFUwBHSf0y6S5yXzN/gbcIGFZArwIn/w0kch7PIANh 7tE0Um7IORwHzikROPLBFcA79iS9BnPI3V/SSxAZiFKaO3sCXm1RPwdWom3ewo9t cjE3JLTt/xa7kSuAjpoP/ypChHauPqUVyiyT8ebu+MsTMY38MujRu1CEoubChaVC KGluvwARAQABiQEfBBgDAgAJBQJdzl58AhsMAAoJEFIwm8q5Koli85sH/A05Hzhl ClCdqIwfPvNWmxA58X5mfqI50ClQUhv5N8hqObHhbE/0mwzbDKTjS8dz+uCzNzsI lzGkL4e/NtljC8gXrUIxGiu0S+2LoAVDhX/R9vY6M46R0oIwwIySSNk62/HrQyil v1jdgOgv03u/EXOhv/zInPaCaw+M9cYfcHWU9IOPEkvEqCXwEOWIvyQGAc/6SuNL B/YUXsbyqFa53v/Js4NIXedDZ3dG2drRYrxKs9x0uMmU19OgAX7yx5vOYWCyGYJs 9UHcpQxi6vhbDB8IczYYwFdZ8dp1xMbbKCgCn4FyujSDdV42S4FieLROzhk+M1ew Jtdi28NJcvRZKko= =OoBA -----END PGP PUBLIC KEY BLOCK-----';
$privatekey = '-----BEGIN PGP PRIVATE KEY BLOCK----- Version: BCPG v1.64
lQPGBF3OXnsDCADInJcfC0JchkD6MsGlPYkywLX4IsKPtcG7YKNR7+55qdV9NDad jDll5FTGKwPbQxzKL5N/Um4T21xwN6quZu9x3a9W8gfiC75IkGpcE90pUEZ0qE9b rGe2ipc80rCWeji0FEjP0CfDTXGZGe4Knh5pAQBvgDdFSaDFd1M3NRp8cpTCUXrv Jt005G4bOUf3ZMAqcoRsGsK1GvjCiSs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