how to encrypt and decrypt using public and private key gnupg in php code example
Example: php pgp
<?php
// Using PHP with PGP.
// (c) Kelv 2000
$username = "dummy"; // Your username on the server
$pgp="/usr/local/bin/gpg"; // path to GnuPG
// Where the encrypted mail comes from. Dummy address from your keyring.
$from="Example.com website <[email protected]>";
// The recipient. This is the imported address from your public key.
$recp="Example orders <[email protected]>";
// The data to be encrypted
$data="Text that will be encrypted";
$command = 'echo "'.$data.'" | '.$pgp.' -a --always-trust --batch "
$command.= '--no-secmem-warning -e -u "'.$from.'" -r "'.$recp.'"';
$oldhome = getEnv("HOME");
putenv("HOME=/home/$username");
$result = exec($command, $encrypted, $errorcode);
putenv("HOME=$oldhome");
$message = implode("\n", $encrypted);
// $message now contains the encrypted data.
$subject="New order from example.com website";
$header="From: {$from}";
mail($recp,$subject,$message,$header);
?>