I'm trying to take an uploaded image, encrypt the image, store it in MySQL, then decrypt it for display when an authorized person requests to see it.
Here's how I'm currently encrypting:
$image = addslashes(file_get_contents($_FILES['users_image']['tmp_name'])); $enc_image = encrypt($image, "long secret random key");
Then I store the
$enc_image in a MySQL BLOB field. When I try to decrypt it and print it goes like so:
$img = decrypt($rec['file'], "long secret random key"); echo '<img src="data:image/jpeg;base64,'.base64_encode($img).'"/>';
I'm using this code from this Stackoverflow answer, and I'm seeing the decrypted base-64 text, in my output, but it doesn't display via HTML. Here is a sample encrypted image's attempt at being recovered: https://pastebin.com/miDCP3Gz
NOTE: My "long secret random key" includes a hashed random unique salt, but I am sure I am encrypting and decrypting with the same string.
Any idea why this wouldn't be displaying correctly?