-1

I am looking for a way to store OpenSSL encrypted data in my MySQL database. When I store it, i can't retrieve the original string after, since it isn't storing the strings correctly.

Of course, I could save is base64 encoded and decrypt it later, which works like a charm. However, looking at efficiency I would like to know if there is a better way, since base64 encoding is eating disk space for storage.

Thanks for your advice

jww
  • 83,594
  • 69
  • 338
  • 732
  • 4
    Instead of asking a generic question, show the current code of encrypting text, storing it, and trying to retrieve it, and describe the error in a detail. – Shadow Feb 05 '17 at 22:12
  • And also the table definition. – user207421 Feb 05 '17 at 22:32
  • OpenSSL is not an encryption method, it is a library that supports many encryption algorithms. Which one are you using. Also supply the code you have that is not working along with sample data/keys, modes, IV & etc. – zaph Feb 05 '17 at 22:45
  • 1
    And the result of encryption isn't a string, it is binary data. – user207421 Feb 06 '17 at 01:26
  • 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:32
  • @jww I thought that I was rather specialized with my gold crypto & encryption badges but your openssl badge easily trumps that :) – Maarten Bodewes Mar 07 '17 at 16:04

1 Answers1

3

Yes, you can store the encryption results as BINARY or VARBINARY, that way you don't loose the base64 overhead.

Maarten Bodewes
  • 80,169
  • 13
  • 121
  • 225