title: Data corruption mysql with openssl
body: <p>I use openssl to encrypt a text, then put this into a mysql database.
  This works fine, however with long texts, the decrypted text becomes corrupted.</p>
  
  <p>Personally I think this is due to the way mysql saves this text into the database, there are a lot of not alpha numeric characters in the encrypted text. But I am not sure about that.
  Also I don't know which collation to use in mysql, right now I set it to *utf8_unicode_ci*, but still there is corruption of data.</p>
  
  <p>A live example can be seen here: <a href="http://todolist.x10.mx" rel="nofollow">http://todolist.x10.mx</a></p>
  
  <pre><code>Username: example
  Password: password
  </code></pre>
  
  <p>To view the corrupted data, click <code>Download Backup</code>.</p>
  
  <p>Below the code, of course <code>$encrypted</code> is saved into the database. This code works fine without database.</p>
  
  <pre><code>&lt;?php
    $source = 'very long text';
    $iv = "1234567812345678";
    $pass = 'difficultpassphrase';
    $method = 'aes-256-ofb';
  
    $encrypted = openssl_encrypt ($source, $method, $pass, true, $iv);  
    echo $encrypted;
  
    $decrypted = openssl_decrypt ($encrypted, $method, $pass, true, $iv);
    echo $decrypted;
  ?&gt;
  </code></pre>
  
  <p>Thank you in advance for your time and expertise.</p>