Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: GnuPG: users

RE: PHP Script

 

 

GnuPG users RSS feed   Index | Next | Previous | View Threaded


JCochran at hearstnp

Oct 2, 2009, 3:50 PM

Post #1 of 1 (335 views)
Permalink
RE: PHP Script

http://www.phpclasses.org/browse/package/245.html



I got this working with the above code.



~ Jason



Midland Reporter Telegram

Direct: (432) 687-9011 (x 3111)

www.mywesttexas.com <http://www.mywesttexas.com>



From: Cochran, Jason L
Sent: Friday, October 02, 2009 5:21 PM
To: 'gnupg-users [at] gnupg'
Subject: PHP Script



I need help getting a scrip working. I am hosted with Hostgator. My key
is in the cpanel. Yet I can't get php to work with it.



PHP_INFO: http://gator1028.hostgator.com/~mwtadmin/php_info.php

SCRIPT: http://gator1028.hostgator.com/~mwtadmin/pgp_test.php



Thanks!



===== pgp_test.php =====

<?php



// replace this with the user name or e-mail address that you used
for your PGP key pair

$pgpuser = "webmaster [at] mywesttexas" ; // The email used to
generate your public key



// Recipient of the email

$testemail = "jcochran [at] mrt";



// Replace with your subject

$emailsubject = "Encrypted Email Subject";



// The from field

$emailfrom = "From: webmaster [at] mywesttexas";



// Feed your text in here

$body = "To test if your decryption work, put some text here or feed
in the variables from your submitted forms";



// Tell gnupg where the public key is that is should use to encode
your message

// This is usually in your home directory, below the public_html
(mine is .gnupg)

// change this to the correct path of your web space. On hostgator:
home/username/.gnupg

putenv("GNUPGHOME=/home/mwtadmin/.gnupg");



// create a temporary, unique file name to work from

$infile = tempnam("/tmp", "PGP.asc");

$outfile = $infile.".asc";



// we write the various bits and bobs into the temp file

$fp = fopen($infile, "w");

fwrite($fp, $body);

fclose($fp);



// Call the other directory of gnuGP (this will work on hostgator)
and run the command

// When you call this line, it will set off the actuall encoding
process

$command = "/usr/bin/gpg -a -always-trust -batch -no-secmem-warning
-e -r $pgpuser -o $outfile $infile";



// Call the line that will encrypt your temporary file

system($command, $result);



// The encryption is now loaded in the system, so delete the temp
file

//unlink($infile);



if ($result == 0) {

$fp = fopen($outfile, "r");



if (!$fp || filesize($outfile) == 0) {

$result = -1;



} else {



// read the encrypted file

$contents = fread ($fp, filesize ($outfile));



// delete the encrypted file

unlink($outfile);



// send the email and write something nice if it was a success

// otherwise moan bitterly and wonder what went wrong

// Errors are usually either your username, or more like the paths
to your gnuGP

// contact your Tech Support for your paths - the ones shown here
works for hostgator.

mail ($testemail, $emailsubject, $contents, $emailfrom);



print "Thank you!! Your encrypted booking information has been
sent.";



}

}



if ( $result != 0) {



print "There was a problem processing the information.";



}



?>



~ Jason



Midland Reporter Telegram

Direct: (432) 687-9011 (x 3111)

www.mywesttexas.com




========================================================
This e-mail message is intended only for the personal
use of the recipient(s) named above. If you are not
an intended recipient, you may not review, copy or
distribute this message.

If you have received this communication in error, please
notify the sender immediately by e-mail and delete the original message.
========================================================

GnuPG users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.