#!/usr/bin/perl use strict; use warnings; use Crypt::Rijndael; use Crypt::CBC; my $my_key = $ARGV[0]; my $plainfile="test2.txt"; my $cipher; my $buffer; my $decrypted="$plainfile.cry.txt"; # this sub makes all keysize of 32 bytes, in case the key you give is # smaller. However, remember to use a strong key !!! sub get32 { my $data = shift; return "\0" x ( 32 - length($data)%32 ) . $data; } #-------------------------------------------------------------------- # Parameters #-------------------------------------------------------------------- $cipher = Crypt::CBC->new( {'key' => get32($my_key), 'cipher' => 'Rijndael', 'iv' => '§%(Ml7!B', 'regenerate_key' => 1, 'padding' => 'standard', 'prepend_iv' => 0 }); #-------------------------------------------------------------------- # Encryption #-------------------------------------------------------------------- open(FH_plain,"./$plainfile"); open(FH_crypted, ">$plainfile.cry"); while (read(FH_plain,$buffer,1024)) { print FH_crypted $cipher->encrypt($buffer); } close FH_plain; close FH_crypted; #-------------------------------------------------------------------- # Decryption #-------------------------------------------------------------------- open(FH_crypted, "<$plainfile.cry"); open(FH_decrypted, ">$decrypted"); while (read(FH_crypted,$buffer,1024)) { print FH_decrypted $cipher->decrypt($buffer); } close FH_crypted; close FH_decrypted;