开发者

php script to call gpg commands

开发者 https://www.devze.com 2022-12-23 05:04 出处:网络
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.phpUsing the Crypt_GPG pack

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

精彩评论

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

关注公众号