Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I finally found the solution to my problem.</p> <p>Thanks to both of you guys though, your answers did help out. I did follow your advice to encode/decode in base64 and therefore avoid any plain-text encoding problems.</p> <p>What I had to do in order to make the decryption work is add <strong>'header' => 'randomiv'</strong> to my Perl script's cipher creation, since PEAR's Crypt_CBC class uses a Random IV when encrypting.</p> <p>I found that particular parameter in <a href="http://search.cpan.org/~lds/Crypt-CBC-2.24/CBC.pm" rel="nofollow noreferrer">Crypt::CBC's documentation</a>.</p> <p>Also, looking directly into CBC.php's decrypt function, I found what it did in order to determine the IV: Take the header's ('RandomIV') length, and use it as an offset to substr the encrypted string up to the <em>blocksize</em>'s value (8 by default). I also specified the <em>keysize</em> (56 by default) for good measure.</p> <p>For completeness' sake and for reference, here are both of my updated test scripts:</p> <h3>PHP (cryptTest.php):</h3> <pre><code>require_once('Crypt/CBC.php'); $key = "8326554161EB30EFBC6BF34CC3C832E7CF8135C1999603D4022C031FAEE"; $cipher = new Crypt_CBC($key, 'BLOWFISH'); $encrypted = $cipher-&gt;encrypt($text); if (PEAR::isError($encrypted)) { echo $encrypted-&gt;getMessage(); } else { echo "ENCRYPTED STRING: " . base64_encode($encrypted); } </code></pre> <h3>PERL (decryptTest.pl)</h3> <pre><code>use Crypt::CBC; use MIME::Base64; my $encrypted = decode_base64("UmFuZG9tSVbrNE3ony00FlUbiprLn0fu"); my $key = "8326554161EB30EFBC6BF34CC3C832E7CF8135C1999603D4022C031FAEE"; my $header_spec = "randomiv"; my $blocksize = 8; my $keysize = 56; my $iv_offset = length $header_spec; my $iv = substr $encrypted, $iv_offset, $blocksize; my $cipher = Crypt::CBC-&gt;new( {'key' =&gt;$key, 'cipher' =&gt; 'Blowfish', 'iv' =&gt; $iv, 'header' =&gt; $header_spec, 'prepend_iv' =&gt; $iv_offset, 'blocksize' =&gt; $blocksize, 'keysize' =&gt; $keysize }) my $plaintext = $cipher-&gt;decrypt($encrypted); print $plaintext; </code></pre> <p>There you go. Again, thanks a lot!</p> <p>Mathieu</p>
 

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