开发者

php script to call gpg commands

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜