Category: Email
Author/Contact Info Chris Prosser chrisprosser@earthlink.net
Description: This is a program for sending a PGP encrypted email - Of course this requires that you have the public key of the person to whom you wish to send. Steps: 1) DL said persons cert (probably best in PKCS#7 format -- that is what I'll use here at any rate). 2) Use openssl to convert to PEM.: (eg. uses a verisign cert.) openssl pkcs7 -print_certs -inform DER -outform PEM -in <your.cert.p7c> -out <your.cert.pem> 3) Use the code (it requires a tool called smime -- http://www.bacus.pt/Net_SSLeay/smime.html * I think that most recent versions of openssl now have an smime function.
#!/usr/bin/perl -w
use strict;
use CGI;

my $cgi = CGI->new();

my $certpath    = "/path/to/where/you/store/certs";
my $sendmail    = "/path/to/smime-0.7/send.pl"; #comes w/ smime for yo
+ur convenience
my $smime       = "/path/to/smime-0.7/smime";
my %cert        = (
                   'chrisprosser@earthlink.net' => "$certpath/chrispro
+sser_earthlink_net.pem"
                  );
my $to          = $cgi->param('to')      || 'your@defaultaddr.com';
my $from        = $cgi->param('email')   || 'your@defaultuseradder.com
+';
my $subject     = $cgi->param('subject') || "Encrypted Email";

my @field = $cgi->param();
my $message = undef;

# Loop through any of the fields sumbit to cgi
foreach(@field) {
        my $field = $_;
           $field =~ s/_/ /go;
        $message .= "$field".("."x(15-length($_)+1)).": ".$cgi->param(
+$_)."\n\n";
}

{
   open(TXT, "|$smime -m text/html | $smime -e $cert{$to} | $sendmail 
+'$subject' $to $from >/dev/null");
      local $/=undef;
      print TXT $message;
   close(TXT);
}

exit;
Replies are listed 'Best First'.
Re: S/MIME Encrypted Email
by Adam (Vicar) on Jan 26, 2001 at 22:19 UTC
    Please use <code> tags around your code. Then it would look like this:
    #!/usr/bin/perl -w use strict; use CGI; my $cgi = CGI->new(); my $certpath = "/path/to/where/you/store/certs"; my $sendmail = "/path/to/smime-0.7/send.pl"; #comes w/ smime for yo +ur convenience my $smime = "/path/to/smime-0.7/smime"; my %cert = ( 'chrisprosser@earthlink.net' => "$certpath/chrispro +sser_earthlink_net.pem" ); my $to = $cgi->param('to') || 'your@defaultaddr.com'; my $from = $cgi->param('email') || 'your@defaultuseradder.com +'; my $subject = $cgi->param('subject') || "Encrypted Email"; my @field = $cgi->param(); my $message = undef; # Loop through any of the fields sumbit to cgi foreach(@field) { my $field = $_; $field =~ s/_/ /go; $message .= "$field".("."x(15-length($_ +1)).": ".$cgi->param( +$_)."\n\n"; } { open(TXT, "|$smime -m text/html | $smime -e $cert{$to} | $sendmail +'$subject' $to $from >/dev/null"); local $/=undef; print TXT $message; close(TXT); } exit;
A reply falls below the community's threshold of quality. You may see it by logging in.