#! /usr/bin/perl -w
use strict;
use autodie;

use Crypt::CBC;
use Getopt::Long;

my %options = (cipher => 'Rijndael', 'cipher-key' => 'BlahBlahBlahBlah');
GetOptions(
    \%options => qw(
        cipher-key|cipher_key|k=s
        password|p=s
        file-name|file_name|f=s
    )
);

if (! $options{password}) {
    # We'll try to read the password from a echoless STDIN
    eval "use Term::ReadKey";
    if ($@)  {
        die "Cannot load 'Term::ReadKey', no way to read password safely!\n";
    }
    ReadMode('noecho');
    print "Geef het password: ";
    chomp($options{password} = ReadLine(0));
    ReadMode('restore');
    print "\n";
}

my $cipher = Crypt::CBC->new(cipher => $options{cipher}, key => $options{'cipher-key'});

open my $fh, '>', $options{'file-name'};
print $fh $cipher->encrypt($options{password});
close($fh);
