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
  • Would there be security problem even if you can do this, even if you can do this? Who ever you want to protect the file content from can also read you source of your JS, right? Commented Dec 17, 2009 at 14:46

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

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.

Comments

2

The accepted answer is outdated here. It is possible to do this now using HTML5 File API and something like the CryptoJS library.

Comments

0

I can't speak to other browsers, but I know this should be possible in Firefox by using the file manipulation api to upload/download files from the user to the client-side code (where they may be manipulated), and standard ajax to upload/download files from the client-side code to the server.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.