views:

88

answers:

3

I wrote a PHP script which will run every Monday using cron. In this email I am attaching an XLS document which contains sensitive information. What is the best way to secure this email? Can I set a password on the XLS document? Can I encrypt the email and only allow the correct receiver to have authorization to open it?

I am using PHPExcel to create the XLS docuement, in case this helps.

Thanks for any help!
Metropolis

+1  A: 

You could encrypt this e-mail with the recipient's public key/certificate using GPG or S/MIME.

This could be a good starting point: http://www.php.net/manual/en/function.openssl-public-encrypt.php

Bruno
+5  A: 

Encrypting the email is the most secure way to do it IMHO. If you have control of the server you can install GPG and call it from the command line to encrypt the email with a secret key. The downside is the recipient will require a plugin to their email client and the public key to decrypt the message with.

A slightly less secure way but easier on your end user is to send a plain email containing a link for the person to download the XLS file. The XLS file is then stored behind a password protected area. Use HTTPS to encrypt the page and the download. Additionally you could create a one time HASH using MD5, or better, SHA256 that is generated by the PHP script and stored in a database in relation to the file. Send that as a link parameter and have it expire. That makes it much more difficult for an unintended person to access the link.

The second method also has the benefit of being available on any host that will let you do SSL. No need to have special access to the server.

Cfreak
+1 for mentioning e-mailing a link
Mark Baker
If I was to encrypt the email using GPG, do all email clients need a plugin to make the process easy for the client? The best solution may very well be what you suggested about keeping the file behind a password protected area.
Metropolis
@Metropolis: yes all clients would need a plug-in.
Cfreak
+1  A: 

PHPExcel don't support passwords (yet) and AFAIK passwords on Excel files are not 100% secure (only Office 2007+ are good at securing files). The best way would be to encrypt the file before attaching it to the email and then decrypt it after you receive it. If you can encrypt it with GnuPG under your PHP installation (see this) there is a plugin for Thunderbird and Seamonkey mail clients called Enigmail which will automate the decryption process.

AlexV
I will not be able to get GnuPG installed on the host that we are using alex. If I use openssl_public_encrypt, are there plugins for that encryption type? Also, how can I encrypt the file being sent? It seems like these things only encrypt data.
Metropolis
No, I'm not aware of other plugin for other types of encryption. You can encrypt a file with openssl_public_encrypt. Just load the content of the file with something like file_get_contents, encrypt it with openssl_public_encrypt then write the encrypted result with something like fwrite and finally attach this file to your email.
AlexV
I need the file to be in xls format though. If I encrypt the data in this way, and not use PHPExcel, will that still work? Or is there a way to output the encrypted data using PHPExcel?
Metropolis
1) You create your file with PHPExcel and save it on your server somewhere. 2) You encrypt the file as I shown in previous comment. 3) You save (overwrite or save in another file) the encrypted file. 4) You attach the encrypted file to your email. 5) The customer that receive the email must decrypt the file he received (probably with an app you will have made for him). 6) After the decryption the file is readable in Excel.
AlexV