views:

140

answers:

2

I'm just sounding things out about this having looked around for a while and drawn a blank. I'd like to see if this is even possible as so far I can't see a way to do it.

I want to encrypt a file locally (in the browser using existing libraries) before uploading it. Then I'll need to retrieve it and decrypt it before presenting the file to the user. Specifically, I can't send the file to the server for encryption before storage. Encryption/decryption needs to be performed client side.

Here's a rough flow of what I need to do:

  1. Present user with a find-file widget.
  2. Read file into client side script (i.e. load it locally)
  3. Encrypt it on the client.
  4. Upload encrypted version, flush the client side and store the data.

And, in reverse:

  1. Download the stored, encrypted version of the file.
  2. Decrypt it on the client.
  3. Present the decrypted file back to the user as a download.

I've been looking for some kind of MIME encoding on the client (similar to the way email attachments are MIME encoded before being sent as plain text). I'm particularly interested in a jQuery method, as that's what the rest of my app is using, but plain old javascript would be fine.

Any thoughts or pointers very gratefully received. This is the one I'm mulling over the holidays. So, thanks in advance for any comments.

+1  A: 

You can't do this with JavaScript. You can, of course, simply use SSL (e.g., via HTTPS). Dead easy, well-tested, all of that. Otherwise, you'll have to use something non-standard like Flash, Java, or ActiveX.

T.J. Crowder
+1  A: 

There is no way to do this using plain Javascript or JQuery due to security restrictions in the browser.

Your best bet is probably taking a open source Flash based upload component like SWFUpload (Flash can much more or the client side) and adding the encryption routines there in ActionScript. Creating a Java applet or an ActiveX control are also valid options.

Depending on what kind of encryption we are talking about, there also may exist ready-made components for the job.

Pekka
I was beginning to think so. Thanks. I have no problems looking at Flash, so I'll investigate that. Thanks Pekka.
Mark