A file has been encrypted by Perl. Initial decrypt attempts failed and I am now trying to ascertain whether there is any hoojoo going on (some other settings required)
Duff Perl Code:
use strict;
use Crypt::Rijndael;
my $key ='...';
my $rcipher = Crypt::Rijndael->new ($key, Crypt::Rijndael::MODE_CBC());
undef $/;
my $encrypted = <>;
print $rcipher->decrypt($encrypted);
C# Decryption Implementation
CryptoStream decryptor = null;
StreamReader srDecrypt = null;
FileStream fsIn = null;
RijndaelManaged rijndaelCipher = null;
string fileContents;
try
{
rijndaelCipher = new RijndaelManaged();
rijndaelCipher.Mode = CipherMode.CBC;
rijndaelCipher.Key = Encoding.UTF8.GetBytes(Password);
rijndaelCipher.IV = Encoding.UTF8.GetBytes(Password);
rijndaelCipher.Padding = PaddingMode.None;
fsIn = new FileStream(FilePath, FileMode.Open);
decryptor = new CryptoStream(fsIn, rijndaelCipher.CreateDecryptor(), CryptoStreamMode.Read);
srDecrypt = new StreamReader(decryptor);
fileContents = srDecrypt.ReadToEnd();
}
finally
{
if (decryptor != null)
decryptor.Close();
if (fsIn != null)
fsIn.Close();
if (srDecrypt != null)
srDecrypt.Close();
if (rijndaelCipher != null)
rijndaelCipher.Clear();
}
How Perl Code should read
binmode OUTF;
my $key ="..."; # Your secret key
my $rcipher = Crypt::Rijndael->new ($key, Crypt::Rijndael::MODE_CBC());
$rcipher->set_iv($key); # You may wish this IV to be something different from the Secret Key
my $plaintext = "Please encrypt me"; # Your string to be encrypted
if(length($plaintext) % 16 != 0 ) {
$plaintext .= ' ' x (16 - (length($plaintext) % 16)); }
my $rencrypted = $rcipher->encrypt($plaintext);