title: PHP decrypt not working using mcrypt_decrypt?
body: <p>Seems that <code>mcrypt_decrypt</code> <strong>can't proper decrypt my string</strong> (all works fine in <code>var_dump</code> except when decrypting - <code>load_decrypted</code> value is wrong). Any help would be appreciated.</p>
  
  <pre><code>array
    'salve_plain' =&gt; string 'a:1:{s:8:"modified";i:1321974656;}' (length=34)
    'save_encrypted' =&gt; string '^ånÄc¥JŸRæk®»}J%áR–y #‡nwZX\µÚ™È§œ‘5‚&lt;_¹M¿ÔT9î»ªk)…ª  Ø' (length=64)
    'save_encoded' =&gt; string 'XuVuxGOlA0qfUuYXa667fUoSEyXhBVKWeSAjh253EFpYXLUS2pnIp5yRNa3LgjxfuRNNv9RUOe67qmsphaoJ2A==' (length=88)
  
  array
    'load_undecoded' =&gt; string 'XuVuxGOlA0qfUuYXa667fUoSEyXhBVKWeSAjh253EFpYXLUS2pnIp5yRNa3LgjxfuRNNv9RUOe67qmsphaoJ2A==' (length=88)
    'load_decoded' =&gt; string '^ånÄc¥JŸRæk®»}J%áR–y #‡nwZX\µÚ™È§œ‘5‚&lt;_¹M¿ÔT9î»ªk)…ª    Ø' (length=64)
    'load_decrypted' =&gt; string '-dœÞ{*€ ¥ûü(1À�ðú-›(!*»ÓÍW¦;}' (length=34)
  </code></pre>
  
  <p>PHP <code>load()</code> function:</p>
  
  <pre><code>private function load()
  {
  
      // Decoding
      $plain = file_get_contents($this-&gt;filename);
      $decoded = base64_decode($plain);
  
      // Decrypting
      $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
      $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
      $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($this-&gt;secret),
          $decoded, MCRYPT_MODE_CBC, $iv));
  
      // Deserializing &amp; loading
      $this-&gt;data = unserialize($decrypted);
      var_dump(array('load_undecoded' =&gt; $plain, 'load_decoded' =&gt; $decoded,
          'load_decrypted' =&gt; $decrypted));
  }
  </code></pre>
  
  <p>PHP <code>save()</code> function:</p>
  
  <pre><code>private function save()
  {
  
      // Serialization
      $serialized = serialize($this-&gt;data);
  
      // Encrypting
      $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
      $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
      $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($this-&gt;secret),
          $serialized, MCRYPT_MODE_CBC, $iv);
  
      // Encoding &amp; saving
      $encoded = base64_encode($encrypted);
      file_put_contents($this-&gt;filename, $encoded);
  
      var_dump(array('salve_plain' =&gt; $serialized,
          'save_encrypted' =&gt; $encrypted, 'save_encoded' =&gt; $encoded));
  
  }
  </code></pre>