-3

So I'm trying to encrypt and echo a file with openssl. Getting my file contents works, but after I call the function to encrypt, it doesn't echo anything, as if it were a syntax error.

$file = file_get_contents($filename);
//echo $file; // works
$encfile = openssl_encrypt($file, $encmethod, $enckey, 0, $iv);
echo $encfile;

Yes, all my encryption keys and everything are valid. Echoing anything after the encryption doesn't work. If anyone knows what's wrong please let me know.

7
  • 2
    Check your error log. Commented Apr 5, 2018 at 0:59
  • Tell us, what are the values of $encmethod, and $iv. Also, what is the byte length of $enckey? Also as requested, check your error log. Commented Apr 5, 2018 at 1:04
  • Do you even have OpenSSL installed with PHP? Commented Apr 5, 2018 at 1:05
  • @MattClark $encmethod = "AES-256-CBC"; $iv is 16 bytes $enckey is 32 and theyre based off of time and worked fine with a smaller file previously. Commented Apr 5, 2018 at 1:06
  • so, what did the logs reveal after what @zerk asked , anything? If you don't have access to logs, then set error reporting to catch and display. What version of PHP also? Commented Apr 5, 2018 at 1:22

2 Answers 2

1

I allowed php more memory with

ini_set('memory_limit','512M');

And now it works like a charm.

Sign up to request clarification or add additional context in comments.

1 Comment

I use ini_set('memory_limit','3G'); on my server lol, really. But it was only for one time, Ususall PHP only has 1G but I had to pull 130million rows out of the DB and move them to MongoDB ... lol
0

I wouldn't add more memory.

I faced a similar issue recently.

How did I fix it, I encrypted chunks of the file at a time a few MB, then I separated the base64 encoded chunks with a : which doesn't appear in base64.

Then when you decode it you read it tell you get the the : decrypt it and move on to the next chunk.

That way you stay well below the memory limit ... :)

See this answer I posted a few days ago KLICK

-note- I use PHPSecLib for AES, we were already using it for sFTP, and I had to update from mycrypt for our Upcoming move to PHP7.

Comments