title: Sending an mcrypt-encrypted string via a URL parameter - decoded text is mangled
body: <p>I'm messing with a simple authorization scheme. I think the easiest way to do it without SSL or other HTTP auth would be a shared key encryption. Adapting a simple example from the PHP manual, I came up with the following:</p>
  
  <pre><code>$text = "boggles the invisible monkey will rule the world";
  $key = "This is a very secret key";
  
  $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
  $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
  
  $enc = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $text, MCRYPT_MODE_ECB, $iv);
  
  $iv = base64_encode($iv);
  $enc = base64_encode($enc);
  
  echo '&lt;a href="temp2.php?iv='.$iv.'&amp;text='.$enc.'"&gt;link&lt;/a&gt;&lt;br /&gt;';
  </code></pre>
  
  <p>The page that receives this request (temp2.php) looks like this:</p>
  
  <pre><code>$key = "This is a very secret key";
  
  $iv = base64_decode($_GET["iv"]);
  $enc = base64_decode($_GET["text"]);
  
  $crypttext = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $enc, MCRYPT_MODE_ECB, $iv);
  
  echo "$crypttext&lt;br&gt;";
  </code></pre>
  
  <p>This gets very close, but it doesn't decode properly-- it echoes</p>
  
  <p><code>boggles the invisible monkey will rule t—;eôügJë</code></p>
  
  <p>I'm not sure what the hangup is, I tried urlencode/urldecode and htmlentities, thinking maybe a character was mangled in the request, but no difference. </p>
  
  <p>Is there something else I'm missing? Perhaps padding?</p>
  
  <p>Thanks</p>