CRYPT:RC5 problem, can't unencrypt

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
 
D

derekg0

Found the problem, looks like if the string you are encrypting is less
then 8 characters it gets all screwy, if you use a 8 character+ string
it works ok. Guess i'll just have to pad my password before encrypting
it.

thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top