views:

31

answers:

2

Is there an easy/straightforward way to extend the file upload class to encrypt files that are being uploaded? Not just encrypting the filename, but rather the data in the file itself.

I'm using mcrypt for db encryption, and would prefer to use the same for file encryption.

Looking through the Upload.php library, I don't see an obvious place where the uploaded file is read which is where I assume I'd shim in the encryption.

Any help/advice would be appreciated.


edit:

What I'm thinking is that somewhere in do_upload() (I'm thinking file_temp) the file gets encrypted before being moved (not copied!) into its final destination. However, I don't see anywhere in Upload.php where the code is working with any of the files' data outside of filename, size, type, etc. Does this approach make sense?

A: 

Rather than encrypting just the upload, use HTTPS/SSL to encrypt the entire connection between the client and server.

mcandre
The connection *is* encrypted already. I need the files to be encrypted when they live on the server. A trucrypt solution does not work in this case, though. Thanks!
stormdrain
Ah, the connection is already encrypted. Then upload the file normally and encrypt it on the server using mcrypt.
mcandre
This is probably what i would have suggested.
DRL
@mcandre: this is precisely what I'm trying to do; what I need help with is *how* to do it within the codeigniter framework (preferably using/modifying the upload class). Thanks again for the responses.
stormdrain
A: 

I decided to forgo modifying the upload class. What I did was after the file was uploaded, open the file, encrypt it, and write it out again.

$f=file_get_contents(BASE_PATH.$fileFullPath) or die ('<script>window.parent.transUpdateFail(\'no gfc'.$fileFullPath.'\');</script>');
$encf=$this->encrypt->encode($f,$this->e_key) or die ('<script>window.parent.transUpdateFail(\'no encrypt\');</script>');
$nf=fopen(BASE_PATH.$fileFullPath,"r+") or die ('<script>window.parent.transUpdateFail(\'no open '.$fileFullPath.'\');</script>');
$fw=fwrite($nf,$encf) or die ('<script>window.parent.transUpdateFail(\'no fwrite\');</script>');
fclose($nf);
stormdrain