Commit b98f8017 authored by marcus-tun's avatar marcus-tun
Browse files

added base64 encoding

parent ff7bb145
......@@ -3,6 +3,8 @@
use strict;
use Getopt::Long qw(:config bundling);
use Crypt::CBC;
use MIME::Base64 qw( encode_base64 );
use MIME::Base64 qw( decode_base64 );
my %opts = ();
my $verbose=0;
......@@ -17,6 +19,7 @@ GetOptions(\%opts, 'help|h',
) or exit;
if (exists $opts{help}) {
......@@ -47,24 +50,33 @@ print ("key: ".$key."\n") if $verbose;
my $encryption_algorithm='Rijndael';
my $cipher = new Crypt::CBC ($key, $encryption_algorithm, -iv=>$iv, -header=>'none');
my $ciphertext= $cipher->encrypt($plaintext);
my $ciphertext= encode_base64($cipher->encrypt($plaintext));
my $perl_iv = $cipher->iv();
#my $perl_pass = unpack('H*', $cipher->key());
my $perl_pass = $cipher->key();
print ('perl_iv: '.$perl_iv."\n") if $verbose;
print ('perl_pass: '.$perl_pass."\n") if $verbose;
#print ('perl_iv: '.$perl_iv."\n") if $verbose;
#print ('perl_pass: '.$perl_pass."\n") if $verbose;
print ("\n");
if (exists $opts{ciphertext}) {
$ciphertext = trim($opts{ciphertext});
print ("Using ciphertext from cmdline\n");
print ("ciphertext: ".$ciphertext."\n") if $verbose;
print ("ciphertext_de64: ".decode_base64($ciphertext)."\n") if $verbose;
my $de_cipher = new Crypt::CBC ($key, $encryption_algorithm, -iv=>$iv, -header=>'asdf');
my $new_plaintext = $de_cipher->decrypt($ciphertext);
my $new_plaintext = $de_cipher->decrypt(decode_base64($ciphertext));
print ("\n");
print ("decrypted: ".$new_plaintext."\n") if $verbose;
## Check if things worked
print ("worked \n") if ($plaintext eq $new_plaintext);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment