Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crypt::CBC decrypt to scalar not file 1

Status
Not open for further replies.

netman4u

Technical User
Mar 16, 2005
176
US
Hello all,

I got the following code of another post:

Code:
use strict;
use warnings;
use Crypt::CBC;
use FileHandle;
Encrypt();
Decrypt();
sub Encrypt {
	open(CT,">ct.dat");
	open(PT,"<pt.txt");

	my $cipher = new Crypt::CBC({'key'         => 't1234',
								 'cipher'      => 'Blowfish',
								 'padding'     => 'space'});
	undef $/;
	print CT $cipher->encrypt(<PT>);

	close(CT);
	close(PT);
}
sub Decrypt {
	open(CT,"<ct.dat");
	open(PT,">pt.dat");

	my $cipher = new Crypt::CBC({'key'         => 't1234',
								 'cipher'      => 'Blowfish',
								 'padding'     => 'space'});
	undef $/;
	print PT $cipher->decrypt(<CT>);

	close(CT);
	close(PT);
}
exit(0)

Works well however I do not want my encrypted file decrypted to a file I want to capture is as a scalar. Tried the following but it did not work:

Code:
my $passwd = PT $cipher->decrypt(<CT>);

Also this command:

Code:
undef $/;

Undefines the default record separator I think. Do I need to redefine in my main program after the subroutines run?

Thanks,

Nick


If at first you don't succeed, don't try skydiving.
 
try like this:

Code:
my $passwd = $cipher->decrypt(<CT>);

- Kevin, perl coder unexceptional!
 
D'oh!
Ummmm...ya thanks! I should have seen that. My marbles get more scrambled every year!

[ponder]




If at first you don't succeed, don't try skydiving.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top