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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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



Jul 3, 2010, 1:20 AM

Post #1 of 2 (2222 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...)

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


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

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

#testing purposes
print $plaintext;

$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=>'');


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

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

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

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

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



#main program

if (($ARGV[0] =~ "-e"))
if (($ARGV[0] =~ "-d"))

The problem is, I keep getting

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


Jul 8, 2010, 9:07 AM

Post #2 of 2 (2174 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