I wanted to know if there exists a somewhat simple, but secure, method to encrypt strings(not passwords), with a password which is not stored on the server, in PHP.
I’ve checked A reversible password encryption routine for PHP, but I’m unsure if it is secure enough if intruders have access to the server and source.
We’re talking about a automatic system where a computer sends a request to a server, which stores information in a log. So I’m thinking I could send the encryption password in the request header, preferably encrypted, but then it would be difficult to decrypt without storing the password somehow on the server. Wait, I think i might be complicating things a bit too much, but I hope you get the idea… It’s meant to keep the information safe, even if hackers have full control over the server.
If I understand you correctly, you aim for a log that is encrypted by the server. The requests are sent in plain, but you’d like to log something like per-user access statistics or the like and you deem this data to be confidential, so it should be encrypted by the server and also be decrypted by the server, if necessary.
If this is the case, it is actually not all too complicated.
Then you will realize that you created a hen-egg problem – the file again needs a password for the server to have access to the key stored inside. But here’s the trick – you will have to enter the key upon server startup manually, and that’s the ephemeral component you need. The password for the file should be out-of-band information (e.g. placed in a physical vault) and nowhere on the computer itself.
An alternative (but potentially less secure because the password would be present in some physical form) is to rely on OS-specific "password vaults" such as Windows’ Isolated Storage.