#!/usr/bin/perl use strict; use warnings; use PerlIO::via::CBC; warn "Not enough arguments, use:\n./aes.pl password de-/encrypt file_name\n" if scalar @ARGV < 3; my ($password, $action, $file_name) = @ARGV; start_up($action, $file_name); sub start_up { my $action = shift; my $file_name = shift; unless (-f $file_name) { print "Can't find $file_name.\n"; exit 0; } crypto($file_name, $action); } sub crypto { my $file = shift; my $action = shift; my $op = $action eq 'encrypt' ? '>' : '<'; my $suffix = $action eq 'encrypt' ? '.aes' : ''; PerlIO::via::CBC->config( 'key' => $password, 'cipher' => 'Rijndael', ); my $fh; open($fh, "$op:via(PerlIO::via::CBC)", "$file$suffix"); if ($action eq 'encrypt') { open(SOURCE, '<', $file) or die $!; print $fh $_ while(sysread(SOURCE, $_, 1024)); close SOURCE; } else { print <$fh>; } close $fh; return 1; }