Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Found the solution!!!</p> <p>In Perl, I had to add after the opening of the output file: </p> <blockquote> <p>binmode $ofh;</p> </blockquote> <p>The padding suggestion was helpful, but in the end I omitted the padding directive and used the default which is PKCS7 in Perl and in C#.</p> <p>My final Perl code looks like this:</p> <pre><code>use strict; use Crypt::CBC; my $ifh; my $ofh; my $cipher = Crypt::CBC-&gt;new( { 'key' =&gt; 'length16length16', 'cipher' =&gt; 'Rijndael', 'iv' =&gt; 'length16length16', 'literal_key' =&gt; 1, 'header' =&gt; 'none', 'keysize' =&gt; 128 / 8 } ); #open input and output file open($ifh,'&lt;', $infile) or die "Can't open $infile for encryption input: $!\n"; open($ofh, '&gt;', $outfile) or die "Can't open $outfile for encryption output: $!\n"; binmode &amp;ofh; $cipher-&gt;start('encrypting'); #write encrypted data to output file while (read($ifh,my $buffer,1024)) { print $ofh $cipher-&gt;crypt($buffer); } print $ofh $cipher-&gt;finish; #close file handles close($ifh) or die "Error closing input file: $!\n"; close($ofh) or die "Error closing output file: $!\n"; </code></pre> <p>and the C# part:</p> <pre><code>RijndaelManaged myRijndael = new System.Security.Cryptography.RijndaelManaged(); myRijndael.Key = System.Text.Encoding.UTF8.GetBytes("length16length16"); myRijndael.IV = System.Text.Encoding.UTF8-&gt;GetBytes("length16length16"); myRijndael.Mode = CipherMode.CBC; // Create a decryptor to perform the stream transform. ICryptoTransform decryptor = myRijndael.CreateDecryptor(myRijndael.Key, myRijndael.IV); //Create the streams used for decryption. FileStream file = File.OpenRead(strInFile); CryptoStream csDecrypt = new CryptoStream(file, decryptor, CryptoStreamMode.Read); StreamReader srDecrypt = new StreamReader(csDecrypt); // Read the decrypted bytes from the decrypting stream string decryptedText = srDecrypt.ReadToEnd(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload