How do I encrypt a file using PHP?

I am backing up a database and emailing it to a user, but I want to encrypt the file before sending it. Whats the best practice for doing this?

Thanks in advance.

A fairly common encryption tool to use that is supported on pretty much any platform is GPG (The GNU Privacy Guard - Both you and the recipient will need to have a GPG utility and then you will need to acquire the public key from the recipient. With that, you can encrypt the data and he can then decrypt it with his accompanying private key.

If this is too much hassle you can off course also go the easy way like putting the dump in a password protected ZIP/RAR file with file name encryption so the password is asked upon opening the file. Although, that’s not nearly as secure as GPG.