user1218403
user1218403

Reputation: 1

using PGP encryption from within PHP

I'm trying to implement pgp encryption from within PHP for the very first time but I'm having a hard time making it work. I hope someone will be able to point me in the right direction. basically, if I do this:

  $gpg = '/usr/bin/gpg';

  $recipient = '[email protected]';

  $encrypted_message =  shell_exec("echo 'a_string_here' | $gpg -e -r $recipient");

  echo $encrypted_message;

it works fine. a public and a private key is installed on the server for [email protected]. however, if I do this, I get a null variable

  $gpg = '/usr/bin/gpg';

  $recipient = '[email protected]';

  $encrypted_message =  shell_exec("echo 'a_string_here' | $gpg -e -r $recipient");

  echo $encrypted_message;

there is only one public key installed for [email protected]. of course, I need this to work for [email protected] which is the recipient of the encrypted string...

thanks in advance

Upvotes: 0

Views: 3538

Answers (1)

You can take a look at this article: http://devzone.zend.com/30/encryption-and-decryption-using-php-and-gnupg/

Note that they base 64 encode the shell_exec result because by default the encrypted message is in binary format (can be changed to ASCII with the -a switch: $gpg -a -e -r $recipient)

Upvotes: 1

Related Questions