views:

191

answers:

4

system() call in php used to call external program .How can i call gpg (gnupg commands) for encryption through php script.

+1  A: 

http://php.net/manual/en/book.gnupg.php

David Dorward
yeh! this manual giving me the gnupg commands but need to know in what way i can use this commands using system() call in php script/code. also what library i have to use for this.thnks for suggetions.
trainee
Don't use system when there is a proper API. It is slow, inefficient, and harder to debug.
David Dorward
A: 

Maybe the article Encryption and Decryption using PHP and GnuPG helps you. It shows how to do it with external calls.

Felix Kling
A: 

What I used for doing such

$filepath = '/path/to/FileToEncrypt.txt';
$output_filepath = $filepath . ".pgp";
$cmdline = PGP_BIN_PATH . " -e -r " . PGP_RECIPIENT . " < $filepath > $output_filepath";

exec ($cmdline,  $stdout, $return);

if ($return != 0) {
   //Something went wrong with execution, report or do wathever needed
}

assumming constants PGP_BIN_PATH defines path to pgp binary and PGP_RECIPIENT is the dest name, I think it must be known by PGP first.

Benoit
A: 

Using the Crypt_GPG package from PEAR ( http://pear.php.net/package/Crypt_GPG ) worked a charm for me a few months ago when I needed to do similar. Using it's API made it much quicker to get things done and also insulated me from making stupid mistakes - namely getting things wrong re getting the arguments/parameters in the wrong order.

kguest