package SLUB::LZA::Rosetta::TA::Crypt;
use strict;
use warnings;
use Crypt::Mode::CBC;
use namespace::autoclean;

# VERSION

# ABSTRACT: module to handle password load/store for ta-tool

our $salt = pack("H16", "There is no security by obscurity!");
sub encrypt {
    my $what = shift;
    my $iv = "74387112"; # length needs to be of 8
    my $c = Crypt::Mode::CBC->new('Blowfish');
    my $password = $c->encrypt($what, $salt, $iv);
    my $password_hex = unpack("H*", $password);
    return $password_hex;
}

sub decrypt {
    my $password_hex = shift;
    my $c = Crypt::Mode::CBC->new('Blowfish');
    if (defined $password_hex) {
        my $iv = "74387112"; # length needs to be of 8
        my $password = pack("H*", $password_hex);
        my $decrypted = $c->decrypt($password, $salt, $iv);
        return $decrypted;
    }
    return;
}
1;
