[prev in list] [next in list] [prev in thread] [next in thread]
List: perl-win32-users
Subject: RE: Encryption question
From: "Stovall, Adrian M." <Adrian.Stovall () durez ! com>
Date: 2002-12-27 21:07:43
[Download RAW message or body]
> -----Original Message-----
> From: Frazier, Joe Jr [mailto:Joe.Frazier@Peopleclick.com]
> Sent: Friday, December 27, 2002 2:49 PM
> To: perl-win32-users@listserv.ActiveState.com
> Subject: Encryption question
>
>
> Anyone have any simple sample code for encryption and
> decryption? I am not sure I get it. I have tried using
> Crypt::CBC =>blowfish (amoung other encryption routines, but
> am unable to decrypt the result given the same key). I just
> am not sure if I am doing it wrong or what.
>
> Basically, I need to encrypt a string, store it in a file or
> the registry, read with another process at some other time
> and decrypt it.
>
>
> I really dont care what type of encryption package (given it
> installs on Win32), itjust needs to be something stronger
> then Mime::Base64 or some simular easy to break encryption or
> obfuscation.
>
> Help!
>
> Joe
I don't know if this will help, and I haven't looked at it in a few
months, but it should give you a hint or two...
<crypt.pl>
#!perl -w
use strict;
use Cwd;
use Digest::MD5;
use Crypt::CBC;
use Crypt::Blowfish;
sub crypter($$$) {
my ($infile,$outfile,$method) = @_;
my $key;
my $data;
print "$infile $outfile $method\n";
#exit;
print "Please enter a cipher key (8-56 characters): ";
$key = <STDIN>;
chomp($key);
my $cipher = Crypt::CBC->new( {'key' => $key,
'cipher' => 'Blowfish',
});
$cipher->start($method);
open (INFILE, "<$infile") || die "Could not open $infile: $!";
binmode(INFILE);
open (OUTFILE, ">$outfile") || die "Could not create $outfile: $!";
binmode(OUTFILE);
if ($method =~ /d/) {
my $count = 0;
while (read (INFILE,my $buffer,8)) {
$data = $cipher->crypt($buffer);
if ($count > 2) {
print OUTFILE $data;
}
$count++;
}
}
else {
while (read (INFILE,my $buffer,8)) {
$data = $cipher->crypt($buffer);
print OUTFILE $data;
}
}
close OUTFILE;
close INFILE;
}
sub usage() {
print "Usage: perl crypt.pl [-e|-d]
<drive:/path/to/input/file.ext> <drive:/path/to/output/file.ext>\n";
print "\nSwitches:\n";
print "\t-e\tEncrypt the input file and write the garbled data
to the output file\n";
print "\t-d\tDecrypt the input file and write the plain-text
data to the output file\n";
print "\nExamples:\n";
print "\tcrypt -e c:/plain.txt c:/encrypted.txt\n";
print "\tcrypt -d c:/encrypted.txt c:/plain.txt\n";
}
if (@ARGV == 3) {
my $method = $ARGV[0];
my $infile = $ARGV[1];
my $outfile = $ARGV[2];
my $file;
my $path;
unless (-f $infile) { die "Input file problem ($infile): $!"; }
if ($outfile =~ /\//) {
$file = (split(/\//,$outfile))[-1];
$path = (split(/$file/,$outfile))[0];
}
else {
$file = $outfile;
$path = cwd();
}
unless (-d $path) { die "Output directory problem ($path): $!"; }
if ($method =~ /^-e/i) {
crypter($infile,$outfile,"e");
}
elsif ($method =~ /^-d/i) {
crypter($infile,$outfile,"d");
}
else {
print "Bad Method\n";
usage();
}
}
elsif (@ARGV == 0) {
usage();
}
else {
print "Wrong number of arguments\n";
usage();
}
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic