D
derekg0
I'm having a problem with decrypting a password after base64 encoding
and writing to a file, closing the file, opening the file unencoding it
and decrypting. any help with this would be appreciated. Also, after
the program is run i'm getting control characters on the next command
prompt, I'm guessing this has something to do with the problem?
Here is my test program and the output below that:
-bash-2.05b# cat testpw.pl
#!/usr/bin/perl
require 5.002;
use FileHandle;
use Crypt::RC5;
use MIME::Base64;
$key = "keyfile";
$rounds = 12;
$ref = Crypt::RC5->new( $key, $rounds );
$rawpw = "test";
print "rawpw $rawpw\n";
$encrypted = $ref->encrypt( $rawpw );
print "encrypted $encrypted\n";
$encpw = encode_base64( $encrypted );
print "encoded $encpw\n";
chomp $encpw;
print "chomped $encpw\n";
$myfile = new FileHandle "> testpw";
if (!defined $myfile)
{
print "$date Error could not open output file\n";
exit 0;
}
print $myfile "$encpw\n";
$myfile->close;
$infile = new FileHandle "< testpw";
if (!defined $myfile)
{
print "$date Error could not open input file\n";
exit 0;
}
$thepw = $infile->getline;
$infile->close;
print "thepw from file $thepw";
$unencpw = decode_base64( $thepw );
print "unencpw $unencpw\n";
$ftppw = $ref->decrypt( $unencpw );
print "ftppw $ftppw\n";
the output is...
-bash-2.05b# ./testpw.pl
rawpw test
encrypted ÂûÂb/
encoded Dpr7vwhiGC8=
chomped Dpr7vwhiGC8=
thepw from file Dpr7vwhiGC8=
unencpw ÂûÂb/
ftppw
-bash-2.05b# ?6c^[[?6c
and writing to a file, closing the file, opening the file unencoding it
and decrypting. any help with this would be appreciated. Also, after
the program is run i'm getting control characters on the next command
prompt, I'm guessing this has something to do with the problem?
Here is my test program and the output below that:
-bash-2.05b# cat testpw.pl
#!/usr/bin/perl
require 5.002;
use FileHandle;
use Crypt::RC5;
use MIME::Base64;
$key = "keyfile";
$rounds = 12;
$ref = Crypt::RC5->new( $key, $rounds );
$rawpw = "test";
print "rawpw $rawpw\n";
$encrypted = $ref->encrypt( $rawpw );
print "encrypted $encrypted\n";
$encpw = encode_base64( $encrypted );
print "encoded $encpw\n";
chomp $encpw;
print "chomped $encpw\n";
$myfile = new FileHandle "> testpw";
if (!defined $myfile)
{
print "$date Error could not open output file\n";
exit 0;
}
print $myfile "$encpw\n";
$myfile->close;
$infile = new FileHandle "< testpw";
if (!defined $myfile)
{
print "$date Error could not open input file\n";
exit 0;
}
$thepw = $infile->getline;
$infile->close;
print "thepw from file $thepw";
$unencpw = decode_base64( $thepw );
print "unencpw $unencpw\n";
$ftppw = $ref->decrypt( $unencpw );
print "ftppw $ftppw\n";
the output is...
-bash-2.05b# ./testpw.pl
rawpw test
encrypted ÂûÂb/
encoded Dpr7vwhiGC8=
chomped Dpr7vwhiGC8=
thepw from file Dpr7vwhiGC8=
unencpw ÂûÂb/
ftppw
-bash-2.05b# ?6c^[[?6c