#!/usr/bin/perl #perl cryptobox.pl use strict; use warnings; use Crypt::CBC; use Term::ReadKey; #required my $box = shift or die("need boxfile: perl cryptobox.pl !\n"); if (-e $box){ my $encrypted; open(BOX, "<", $box); while(){$encrypted .= $_} close(BOX); print "enter the secret key for $box" and my $key = getkey(); my $cipher = Crypt::CBC->new(-key=>$key,-cipher=>"Crypt::OpenSSL::AES"); my $decrypted = $cipher->decrypt($encrypted); print "=======================SECRET MESSAGE=======================\n"; print "$decrypted\n"; print "============================================================\n"; }else{ print "enter the message to encrypt, type return twice to exit:\n"; $/="\n\n"; my $text = ; $/="\n"; print "enter your key for $box" and my $key = getkey('verify'); print "\nRemember this key! it's only stored in your brain!\n"; my $cipher = Crypt::CBC->new(-key=>$key,-cipher=>"Crypt::OpenSSL::AES"); my $encrypted = $cipher->encrypt($text); open(BOX, ">", $box); print BOX $encrypted; close(BOX); } #exit exit(0); # subs sub getkey{ my $verify = shift; my $pw; my $pwLength = 0; #set this to the min password length print ":"; ReadMode('noecho'); my $pw1 = ReadLine(0); ReadMode('normal'); print "\n"; if($verify){ print "verify:"; ReadMode('noecho'); my $pw2 = ReadLine(0); ReadMode('normal'); print "\n"; if ($pw1 eq $pw2) { $pw = $pw1; } else { print "keys don't match!\nkey?"; $pw = getkey(); } }else{ $pw = $pw1; } if (length($pw1) < $pwLength) { print "key needs to be at least $pwLength characters!\nkey?"; $pw = getkey(); } chomp($pw); return $pw; } __END__