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:
- Present user with a find-file widget.
- Read file into client side script (i.e. load it locally)
- Encrypt it on开发者_开发问答 the client.
- Upload encrypted version, flush the client side and store the data.
And, in reverse:
- Download the stored, encrypted version of the file.
- Decrypt it on the client.
- 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.
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.
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.
The accepted answer is outdated here. It is possible to do this now using HTML5 File API and something like the CryptoJS library.
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.
精彩评论