For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2006 > using an system call for decryption









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author using an system call for decryption
DBSMITH@OhioHealth.com

2006-01-10, 4:02 am

All,

I am using gpg ( opensource encryption/decryption tool) to send files via
ftp to a remote site.
In my WIN32 Perl program I am trying to figure how I would do this
equivalent in Unix...

#> cat gpgpass |gpg - - "all the options" newfile encryptedfile
The gpgpass is the password that will enable decryption to occur and it has
to be piped into the gpg binary as above.

Here is my program

#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Net::FTP;
require 5.8.0;
$ENV{"PATH"} = qq(C:\\Perl\\bin:C:\\Documents and
Settings\\mh-hl7:C:\\Program Files\\GNU\\GnuPG\\);

my $p = qq(--passphrase-fd 0);
my $de = qq(--decrypt);
my $outp = qq(--output);
my $ascfile = qq(MHFM.txt.asc);
my $gpgpass = q{};
my $MHfile0 = qq(C:\\temp\\derek);
#my $MHfile1 = qq(C:\\Documents and Settings\\mh-hl7\\MHFM.txt.asc);
my $MHfile1 = qq(C:\\Program Files\\DzSoft\\Perl
Editor\\Samples\\MHFM.txt.asc);
my $pass = qq(C:\\temp\\pass.txt);

sub ftpme {
my $remotehost = "216.54.146.8";
my $remotedir = "cloverleaf";
my $localdir = "C:\\Documents and Settings\\mh-hl7";
my $user = "....";
my $pass = ".....";
my $data = "$ascfile";
my $ftplog = "C:\\temp\\ftpxfer_to_OH.log";

open (FTPLOG, ">$ftplog") or warn "was unable to open FTPLOG $!";
my $ftp = Net::FTP->new($remotehost, Debug => 10)
or do {print FTPLOG "Cannot connect to $remotehost $!";};
$ftp->login($user,$pass) or do {print FTPLOG "Login failed $!";};
$ftp->binary();
$ftp->cwd($remotedir);
$ftp->get($ascfile) or do {print FTPLOG "Get data failed $!";};
$ftp->quit;
}

unlink $MHfile0 or warn "was unable to unlink old file $!";

ftpme();

rename("$MHfile1","$MHfile0") or die "was unable to cp file to $MHfile0
$!";
if ( -s $MHfile0 ) {
open (PASS, "+<$pass") or warn "was unable to open FH $!";
for (;<PASS>;) {
$gpgpass = $_;
}

print $gpgpass | system ("C:\\Program Files\GNU\GnuPG\gpg $p $de $outp
$MHfile0 $ascfile");

# I know the above will not work but this is what it should conceptually
look like.
}
#else {
# print "file $ascfile not present","\n";
# system ("C:\\WINDOWS\\notepad.exe C:\\temp\\pass.txt");
#}

close (PASS) or warn "was unable to close FH $!";

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com