I'm allowing users to upload files to my web server. All of uploaded files are moved outside of the public directory, (later will be moved to AWS).

Currently I encrypt all of the files users upload, and upon retrieval, decrypt them. So, my question is:

What's the point of encrypting files?

I know, this question might seem silly, but really. The only way an attacker can gain access to the non-public directory is if they get access to the web server. Once the attacker does that, he'll have access to all encryption/decryption keys, and all PHP code that is responsible for file security. So, once the attacker is in, file encryption will be just a security theatre.

Is there any way I could make file encryption actually useful? If someone actually gained access to my servers, would it still be possible that files are secure and undecryptable?

  • you're right that the way you describe it being setup makes little sense. it would be safer/more private if the server didn't know the key; e2e it's called...
    – dandavis
    Jan 5, 2017 at 15:37
  • "The only way an attacker can gain access to the non-public directory is if they get access to the web server." - this would be an assumption I would really dig into before taking it as fact.
    – Joe
    Jan 5, 2017 at 19:40
  • Well, I'm pretty sure of it. What other option is there? By getting access to server i mean, ssh or ftp access. If attacker gains FTP access, then the files are safe because encryption keys are stored in the database, but if attacker gains ssh access, then they'll be able to do anything. I'm sure that my code won't allow anyone to gain HTTP access to a non public directory. Jan 6, 2017 at 12:42

2 Answers 2


Encryption might not be required, but you could make it a bit more useful using public-key crypto.

The receiving machine has the public key, and: 1) Encrypts each file with a unique symmetric key 2) Encrypts the symmetric key with the public key. 3) Stores the two encrypted bits together.

The AWS processing machine has the private key, and can reverse the process.

An attack against the receiving machine can't: a) Read previously uploaded files b) Read new files without replacing the code / monitoring the machine in real time.

However an attacker (against the receiving machine), could still: Replace the public key, divert new files into their own store, or whatever they can manage against new files.


What's the point of encrypting files?

erm, you're asking us why you are encrypting files? We don't know. As to whether this would be a good practice - that depends on where the keys are stored. If they are stored at the client, then even if the server is compromised, not ll the data is compromised. Another consideration is whether there are other routes to the data, e.g. if the underlying storage is accessible via a route other than via your server (e.g. in an NFS share or a backup tape). But additional steps would be needed to ensure that the keys are not accessible via the same route.

Is there any way I could make file encryption actually useful?

Without knowing what your criteria for "useful" are, we can't really say - but there are lots of similar questions here which might provide some insights.

  • I agree, at first i wanted to implement the method where users have their own encryption/decryption key, but that would be really uncomfortable for the user. Thanks for the tips. Jan 5, 2017 at 12:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .