1

I have this situation:

When I encrypt a string with OpenSSL and store the encrypted string base64_encoded in my MySQL DB, I can decrypt the string back to original with a select and openssl_decrypt.

However, when I save the encrypted string without base64_encoding it to MySQL (in Order to save storage... base64 is killing...) I can't decrypt it to the original string...

How is this possible on a theoretical basis? It returns me the errors of wrong final block length

P.S. I save the base64_encoded and not base64_encoded string both in a LONGBLOB MySQL column. (Inserting with prepared statements and real_escape_string function of MySQL).

Billal Begueradj
  • 13,551
  • 37
  • 84
  • 109
  • Your problem appears to be getting binary data in and out of MySQL. See questions like [Binary Data in MySQL](http://stackoverflow.com/q/17/608639) and [Calculating total data size of BLOB column in a table](http://stackoverflow.com/q/10648809/608639). Stop treating it like its a C-string. – jww Feb 06 '17 at 22:28
  • *"Inserting with prepared statements and real_escape_string function of MySQL"* - You were told to avoid `real_escape_string` in your question [Binary data not stored properly in MySQL](http://stackoverflow.com/q/42064646/608639). – jww Feb 06 '17 at 22:40

0 Answers0