PHP - Explain how to use PGP with PHP

Explain how to use PGP with PHP.

In most cases GnUPG(GNU Privacy Guard) is recommended rather than Pretty Good Privacy. This is because GnUPG can be used commercially without license. The machine needs to have PHP and GnUPG installed. Shell access required.

- A key pair comprising of public and private key needs to be generated first.
- The GnuPG needs to be configured on the server.
- Using PHP, home path can be set so that GnuPG can find the keyring, and then pipe the data through GnuPG.

Explain how to use PGP with PHP.

Shell access is required to work with concept. SSH is more secure shell access. Also a Linux machine with PGP installed required. A key pair need to be generated which consists of public and private keys. The public key is uploaded to the server and the private key is persisted on the client machine.

Access the shell and type the following:
mkdir .gnupgp
chmod 777 .gnupgp
gpg - -gen-key.

This process creates dummy key pair. Transfer the public key to the server through ftp. The extension is like .asc. Upload it as ASCII. Then type
gpg - -list-keys

Set the permissions for .gnugpg directory. The following commands does this:
cd .gnugp
chmod 666 trustdb.gpg
chmod 604 secring.gpg
chmod 604 random_seed
chmod 644 pubring.gpg
cd ..

Sample code is as follows:
<?php
$descriptorspec = array(
0 => array("pipe", "r"), // STDIN
1 => array("pipe", "w"), // STDOUT
2 => array("file", "error.txt", "a") // STDERR
);

$proc = proc_open("pgp -sfa -z >", $descriptorspec, $pipes);

stream_set_blocking($pipes[1], false);
stream_set_blocking($pipes[0], false);
fwrite($pipes[0], $DATA_TO_ENCRYPT . "nn" . chr(26) . chr(26));
fclose($pipes[0]);

while(!feof($pipes[1]))
         $pgpBuffer .= fgets($pipes[1], 1024);

fclose($pipes[1]);
$return_value = proc_close($proc);

// echo $pgpBuffer;
?>
PHP - Explain how to do user authentication in php.
Explain how to do user authentication in php - The most convenient way to authenticate a user in PHP is to use session.....
PHP - Explain how to set the browser timeout.
Explain how to set the browser timeout - Browser time out can be set using set_time_limit() method......
PHP - Explain how to create random passwords.
Explain how to create random passwords - Generating random passwords in PHP can be done in multiple ways depending on how much security the application demands...
Post your comment