note 119502 added to function.gnupg-encrypt

From: Date: Thu, 23 Jun 2016 14:36:12 +0000
Subject: note 119502 added to function.gnupg-encrypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-205799@lists.php.net to get a copy of this message
Examples Getting Key Information <?php putenv('GNUPGHOME=/home/sender/.gnupg'); // create new GnuPG object $gpg = new gnupg(); // throw exception if error occurs $gpg->seterrormode(gnupg::ERROR_EXCEPTION); // get list of keys containing string 'example' try { $keys = $gpg->keyinfo('example'); print_r($info); } catch (Exception $e) { echo 'ERROR: ' . $e->getMessage(); } ?> Encrypt a Simple Mail <?php // set path to keyring directory // set path to keyring directory putenv('GNUPGHOME=/home/sender/.gnupg'); // create new GnuPG object $gpg = new gnupg(); // throw exception if error occurs $gpg->seterrormode(gnupg::ERROR_EXCEPTION); // recipient's email address $recipient = 'dgar@example.org'; // plaintext message $plaintext = "Dear Dave,\n The answer is 42.\n John"; // find key matching email address // encrypt plaintext message // display and also write to file try { $gpg->addencryptkey($recipient); $ciphertext = $gpg->encrypt($plaintext); echo '<pre>' . $ciphertext . '</pre>'; file_put_contents('/tmp/ciphertext.gpg', $ciphertext); } catch (Exception $e) { die('ERROR: ' . $e->getMessage()); } ?> Decryption The Mail <?php // set path to keyring directory putenv('GNUPGHOME=/home/recipient/.gnupg'); // create new GnuPG object $gpg = new gnupg(); // throw exception if error occurs $gpg->seterrormode(gnupg::ERROR_EXCEPTION); // recipient's email address $recipient = 'dgar@example.org'; // ciphertext message $ciphertext = file_get_contents('/tmp/ciphertext.gpg'); // register secret key by providing passphrase // decrypt ciphertext with secret key // display plaintext message try { $gpg->adddecryptkey($recipient, 'guessme'); $plaintext = $gpg->decrypt($ciphertext); echo '<pre>' . $plaintext . '</pre>'; } catch (Exception $e) { die('ERROR: ' . $e->getMessage()); } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 190.111.113.179 ---- Manual Page -- http://php.net/manual/en/function.gnupg-encrypt.php Edit -- https://master.php.net/note/edit/119502 Del: integrated -- https://master.php.net/note/delete/119502/integrated Del: useless -- https://master.php.net/note/delete/119502/useless Del: bad code -- https://master.php.net/note/delete/119502/bad+code Del: spam -- https://master.php.net/note/delete/119502/spam Del: non-english -- https://master.php.net/note/delete/119502/non-english Del: in docs -- https://master.php.net/note/delete/119502/in+docs Del: other reasons-- https://master.php.net/note/delete/119502 Reject -- https://master.php.net/note/reject/119502 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205799) next »