#!/usr/bin/perl use strict; use warnings; use Crypt::Rijndael; use Crypt::CBC; use Fcntl ":flock"; #-------------------------------------------------------------------- # Parameters #-------------------------------------------------------------------- my $my_key; my $plain_text; my $cipher; my $buffer; my $asr_file = "wd_file"; my $decrypted = "$asr_file.txt"; #line below is an example of the 1850 character line the larger cgi script will build my $asr_line = '2AD11280700007211/28/07 16:27:42TTLASTNAME TTFIRSTNAME T123457895 01011983TT_ADDRESS TTCITY ALTT_ZIP 00106160304F 02450V44443333222211110112WENDY XXXXXX LASTNAME FIRSTNAMEMADDRESS CITY AL12345 0013193412287WXXXXXX@GMAIL.COM '; $my_key = `openssl enc -bf-cbc -d -in key_file.txt -k encrypt`; $cipher = Crypt::CBC->new( {'key' => $my_key, 'cipher' => 'Rijndael', 'regenerate_key' => 1, 'padding' => 'standard', }); #-------------------------------------------------------------------- # Decryption #-------------------------------------------------------------------- open(FH_crypted, "<$asr_file.enc"); #open original encrypted file flock FH_crypted, LOCK_EX; #lock original encrypted file binmode FH_crypted; open(FH_decrypted, ">$decrypted"); #open plain textfile to hold decrypted data flock FH_decrypted, LOCK_EX; #lock original encrypted file binmode FH_decrypted; $cipher->start('decrypting'); while (read(FH_crypted,$buffer,1024)) { print FH_decrypted $cipher->crypt($buffer); #write the decrypted lines to plain text } print FH_decrypted $cipher->finish; close FH_crypted; #close the original encrypted file print FH_decrypted "$asr_line\n"; #add the new line to the plain text file close FH_decrypted; #close the new plain text file #-------------------------------------------------------------------- # Encryption #-------------------------------------------------------------------- open(FH_plain,"./$decrypted"); flock FH_plain, LOCK_EX; #lock plain text file binmode FH_plain; open(FH_crypted, ">$asr_file.enc"); flock FH_crypted, LOCK_EX; #lock new encrypted file binmode FH_crypted; $cipher->start('encrypting'); while (read(FH_plain,$buffer,1024)) { print FH_crypted $cipher->crypt($buffer); } print FH_crypted $cipher->finish; close FH_plain; unlink $decrypted; #delete the plain text file close FH_crypted; #### #!/usr/bin/perl use strict; use warnings; use Crypt::Rijndael; use Crypt::CBC; #-------------------------------------------------------------------- # Parameters #-------------------------------------------------------------------- my $my_key; my $plain_text; my $cipher; my $buffer; my $plainfile = "act"; my $decrypted = "act_decrypted.txt"; $my_key = `openssl enc -bf-cbc -d -in key_file.txt -k encrypt`; $cipher = Crypt::CBC->new( {'key' => $my_key, 'cipher' => 'Rijndael', 'regenerate_key' => 1, 'padding' => 'standard', }); #-------------------------------------------------------------------- # Decryption #-------------------------------------------------------------------- open(FH_crypted, "<$plainfile.enc"); binmode FH_crypted; open(FH_decrypted, ">$decrypted"); binmode FH_decrypted; $cipher->start('decrypting'); while (read(FH_crypted,$buffer,1024)) { print FH_decrypted $cipher->crypt($buffer); } print FH_decrypted $cipher->finish; close FH_crypted; close FH_decrypted;