use strict;
use warnings;
use Crypt::CBC;
use FileHandle;
my $encr_path;
print "Application password and user encryption program.\n
This program takes user input and created encrypted files for\n
the Application to use\n\n";
print "Do you wish to encrypt a password or User ID (enter the number 1 or 2)?\n\n1) Password\n2) User ID\n\n";
my $choice = <STDIN>;
chomp $choice;
if ($choice == 1) {
print "Please enter the number for the type of password you wish to encrypt:\n\n1) CLI Devices\n2)VistaMart Oracle DB\n3) Failover System\n\n";
my $device = <STDIN>;
chomp $device;
if ($device == 1) {
$encr_path = "/opt/app/CLI_DAE/conf/cli_pass.dat";
}elsif ($device == 2) {
$encr_path = "/opt/app/CLI_DAE/conf/vmdb_pass.dat";
}elsif ($device == 3) {
$encr_path = "/opt/app/CLI_DAE/conf/fovr_pass.dat";
}else{
print "Not a valid choice for encryption! Try again\n";
exit 1;
}
print "Please enter the password you wish to encrypt\n\n";
my $passwd = <STDIN>;
chomp $passwd;
Encrypt($passwd,$encr_path);
}elsif ($choice == 2) {
print "Please enter the number for the type of USER ID you wish to encrypt:\n\n1) CLI Devices\n2)VistaMart Oracle DB\n3) Failover System\n\n";
my $device = <STDIN>;
chomp $device;
my $encr_path;
if ($device == 1) {
$encr_path = "/opt/app/CLI_DAE/conf/cli_user.dat";
}elsif ($device == 2) {
$encr_path = "/opt/app/CLI_DAE/conf/vmdb_user.dat";
}elsif ($device == 3) {
$encr_path = "/opt/app/CLI_DAE/conf/fovr_user.dat";
}else{
print "Not a valid choice for encryption! Try again\n";
exit 1;
}
print "Please enter the User ID you wish to encrypt\n\n";
my $userid = <STDIN>;
chomp $userid;
Encrypt($userid,$encr_path);
}else{
print "Not a valid choice! Please try again.\n\n";
exit 1;
}
sub Encrypt
{
my $entity = shift (@_);
my $sub_encr_path = shift (@_);
open(CT,">$sub_encr_path");
my $cipher = new Crypt::CBC({'key' => 't1234',
'cipher' => 'Blowfish',
'padding' => 'space'});
undef $/;
print CT $cipher->encrypt($entity);
close(CT);
exit(0)
}