Crypt-PGPSimple
view release on metacpan or search on metacpan
PGPSimple.pm view on Meta::CPAN
#_____________________________________________________________________________
sub Password {
return shift->_GetSetProperty("strPassword",shift);
}
#_____________________________________________________________________________
sub PlainText {
return shift->_GetSetProperty("strPlainText",shift);
}
#_____________________________________________________________________________
sub EncryptedText {
return shift->_GetSetProperty("strEncryptedText",shift);
}
#_____________________________________________________________________________
sub SignedText {
return shift->_GetSetProperty("strSignedText",shift);
}
#_____________________________________________________________________________
sub Result {
return shift->{'strResult'};
}
#_____________________________________________________________________________
sub ErrDescription {
return shift->{'strErrDescription'};
}
# ###########################################################################
# PRIVATE PROPERTIES
#_____________________________________________________________________________
sub _GetSetProperty {
# private fuction that is used by all the properties to get/set values
# if a parameter is sent in, then the property is set and true is returned.
# if no parameter is sent, then the current value is returned
my $this = shift;
my $fieldName = shift;
my $newValue = shift;
if (defined($newValue)) {
$this->{$fieldName} = $newValue;
} else {
return $this->{$fieldName};
}
return 1;
}
# ###########################################################################
# PUBLIC METHODS
#_____________________________________________________________________________
sub Encrypt {
my ($this) = shift;
my ($return_value) = 0;
# generate the command line
my ($pgp_command) = $this->{'strPgpExePath'}
. " -feat +batchmode +force "
. $this->{'strPublicKey'};
$this->{'strEncryptedText'} = $this->DoPgpCommand($pgp_command,$this->{'strPlainText'});
# if there were results then everything went as planned
if ($this->{'strEncryptedText'} ne "") {
$return_value = 1;
}
return $return_value;
}
#_____________________________________________________________________________
sub Decrypt {
my ($this) = shift;
# assume fail
my ($return_value) = 0;
# generate the command line
my ($pgp_command) = $this->{'strPgpExePath'}
. " -f +batchmode +force";
$this->{'strPlainText'} = $this->DoPgpCommand($pgp_command,$this->{'strEncryptedText'});
# if there were results then everything went as planned
if ($this->{'strPlainText'} ne "") {
$return_value = 1;
}
return $return_value;
}
#_____________________________________________________________________________
sub EncryptSign {
my ($this) = shift;
my ($return_value) = 0;
# generate the command line
my ($pgp_command) = $this->{'strPgpExePath'}
. " -feast +batchmode +force "
. $this->{'strPublicKey'}
. " -u " . $this->{'strPrivateKey'};
$this->{'strEncryptedText'} = $this->DoPgpCommand($pgp_command,$this->{'strPlainText'});
# if there were results then everything went as planned
if ($this->{'strEncryptedText'} ne "") {
$return_value = 1;
}
return $return_value;
}
#_____________________________________________________________________________
sub Sign {
my ($this) = shift;
my ($return_value) = 0;
# generate the command line
my ($pgp_command) = $this->{'strPgpExePath'}
. " -fts +batchmode +force -u "
. $this->{'strPrivateKey'};
$this->{'strSignedText'} = $this->DoPgpCommand($pgp_command,$this->{'strPlainText'});
# if there were results then everything went as planned
if ($this->{'strSignedText'} ne "") {
$return_value = 1;
}
return $return_value;
}
#_____________________________________________________________________________
sub ErrClear {
$strErrDescription = "";
return 1;
}
#_____________________________________________________________________________
sub Reset {
my ($this) = shift;
my ($clear_key_info) = shift || "";
$this->{'strPlainText'} = "";
$this->{'strEncryptedText'} = "";
$this->{'strSignedText'} = "";
$this->{'strResult'} = "";
$this->{'strErrDescription'} = "";
if ($clear_key_info) {
$this->{'strPublicKey'} = "";
$this->{'strPrivateKey'} = "";
$this->{'strPassword'} = "";
}
return 1;
}
#_____________________________________________________________________________
sub DoPgpCommand {
my ($this) = shift;
my ($pgp_command) = shift || "";
my ($pgp_args) = shift || "";
my ($return_value) = "";
# get the filepath settings and set our temp file paths
my ($encrypted_file_path) = $this->{'strPgpTempDir'} . $$ . ".pgp";
my ($stdout_path) = $this->{'strPgpTempDir'} . $$ . ".txt";
$pgp_command .= " > " . $encrypted_file_path;
# UNCOMMENT TO DEBUG
# print $encrypted_file_path . "\n";
# print $stdout_path . "\n";
# print $pgp_command . "\n";
# print $pgp_args . "\n";
# set the environmental variables
$ENV{"TZ"} = $this->{'strPgpTimeZone'};
( run in 1.063 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )