#!/opt/local/bin/perl -w use IO::Socket; use IO::Handle; use MIME::Base64; use Data::Dumper; use POSIX; use Getopt::Long; use strict; require Crypt::CBC; my $msg = "Message_Generated_in_C#"; my $enc_key = "same_as_in_c#_strKey"; my $enc_alg = "Rijndael"; my $cipher = Crypt::CBC->new({ 'key' => $enc_key, 'cipher' => $enc_alg, }); my $base64_decoded_msg = decode_base64($msg); my $decrypted_msg = $cipher->decrypt($base64_decoded_msg); // This is for debug print STDERR " Salt:\n"; &hex_dump($cipher->salt()); print STDERR " Key:\n"; &hex_dump($cipher->key()); print STDERR " IV:\n"; &hex_dump($cipher->iv()); print STDERR " PassPhrase:\n"; &hex_dump($cipher->passphrase()); print STDERR " Block Size: " . $cipher->blocksize() ."\n", " Key Size: " . $cipher->keysize(). "\n\n"; print "$decrypted_msg\n"; // Function for debug sub hex_dump() { my $data = shift; my @chars = split //, $data; my $ctr = 0; my $ascii_str = ''; for my $char (@chars) { if ($ctr % 16 == 0) { print STDERR " $ascii_str\n" if $ascii_str; printf STDERR " 0x%.4x: ", $ctr; $ascii_str = ''; } printf STDERR "%.2x", ord($char); if ((($ctr+1) % 2 == 0) and ($ctr % 16 != 0)) { print STDERR ' '; } if ($char =~ /[^\x20-\x7e]/) { $ascii_str .= '.'; } else { $ascii_str .= $char; } $ctr++; } if ($ascii_str) { my $remainder = 1; if ($ctr % 16 != 0) { $remainder = 16 - $ctr % 16; if ($remainder % 2 == 0) { $remainder = 2*$remainder + int($remainder/2) + 1; } else { $remainder = 2*$remainder + int($remainder/2) + 2; } } print STDERR ' 'x$remainder, $ascii_str; } print STDERR "\n"; return; }