system() call in php used to call external progra开发者_高级运维m .How can i call gpg (gnupg commands) for encryption through php script.
http://php.net/manual/en/book.gnupg.php
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.
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.
精彩评论