CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Using Crypt::CBC - keep getting Ciphertext does not begin with a valid header *error

 



l4teral
User

Jul 3, 2010, 1:20 AM

Post #1 of 2 (1061 views)
Using Crypt::CBC - keep getting Ciphertext does not begin with a valid header *error Can't Post

Hey everyone.


I have written a script to attempt to push data across a socket, and encrypt the data using the Blowfish encryption method.

Here is the raw script that I have so far (work in progress...)

Code
use Crypt::CBC; 
use IO::Socket;

system("cls");

sub encrypter
{
print "key: ";
$key = <STDIN>;
chomp($key);
my $cipher = Crypt::CBC->new( -key => $key,
-cipher => 'Blowfish',
-header => 'randomiv',
-insecure_legacy_decrypt
);
# undef $/;
# print "enter message to encrypt: ";
# $plaintext = <STDIN>;
#chomp($plaintext);

open INPUTDATA, "<inputfile.txt";
$plaintext .=<INPUTDATA>;

#testing purposes
###
print $plaintext;
<STDIN>;
###


$plaintext = $cipher->encrypt($plaintext);


close (INPUTDATA);

open MYFILE, ">coded.txt";
print MYFILE $plaintext;
close (MYFILE);
print "encrypted file written..shh! secret!\n";




#decryption for testing of successful hash. If it didn't hash right, it throws an error in console
##############
open MYFILE, "<coded.txt";
$ciphertext .=<MYFILE>;
my $cipher2 = Crypt::CBC->new( -key => $key,
-cipher => 'Blowfish',
-header => 'randomiv'
);



$ciphertext = $cipher2->decrypt($ciphertext);
###############







#pushes hash out to the socket
$MySocket=new IO::Socket::INET->new(PeerPort=>3333,Proto=>'tcp',PeerAddr=>'127.0.0.1');
$MySocket->send("$plaintext\n");

}


sub decrypter
{
$key = $ARGV[1];
print "\n*\n*listening with key as $key\n";


my $sock = new IO::Socket::INET (
LocalHost => '127.0.0.1',
LocalPort => '3333',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
);
die "Could not create socket: $!\n" unless $sock;


my $new_sock = $sock->accept();
while(<$new_sock>)
{
$ciphertext = $_;
chomp($ciphertext);
my $cipher2 = Crypt::CBC->new( -key => $key,
-cipher => 'Blowfish',
-header => 'randomiv'
);


$ciphertext = $cipher2->decrypt($ciphertext);

# system("cls");
print "\n$ciphertext";
}

close($sock);



&decrypter;
exit();
}


#main program

if (($ARGV[0] =~ "-e"))
{
&encrypter
}
if (($ARGV[0] =~ "-d"))
{
&decrypter
}



The problem is, I keep getting

Code
Ciphertext does not begin with a valid header for [header] header mode at (script error line)

errors randomly, and it seems to happen more frequently, based on how long the data is to be sent.

This only says that it's hitting a snag somewhere, and encountering more data to encrypt is like "duh" its going to hit it more often. Can anyone point out anything obvious that is wrong with my code? Feel free to run it.

You'll need two instances of it running. one, with a -d [passphrase] option, and the other with a -e option, as it will prompt you for the password to salt the hash with.


I'm really stumped on this, and extremely frustrated, because it should work!!!!! Any help would be greatly appreciated


l4teral
User

Jul 8, 2010, 9:07 AM

Post #2 of 2 (1013 views)
Re: [l4teral] Using Crypt::CBC - keep getting Ciphertext does not begin with a valid header *error [In reply to] Can't Post

nobody knows? :(

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives