This is the simple code to upload a file to azure cloud storage where submitButton_Click uploades the file to blob.
Now i want to encrypt this file on client side using javascript and then upload it to cloud, i wrote a simple javascript that can encrypt the file but i'm not a getting a way to upload the output to cloud
<input type="password" id ="passwd" size="30" />
<input type="file" name="filedata" onchange="handleFiles(this.files)"/>
<input type="button" id="encrypt" value ="Encrypt" onclick="encrypt()"/>
encrypt function
function encrypt() {
var reader = new FileReader();
reader.onload = function (e) {
var filedata = e.target.result;
var encfile = EncryptStr(filedata, document.getElementById("passwd").value, 32);
Save(encfile);
};
reader.readAsBinaryString(file);
}
the function which saves the file on local machine
this gives me the output which directly gets stored on the local machine, now i want to modify the code so that the output is uploaded directly to the server.
why would you encrypt in the client? client code can be easily obtained and your encryption algorithm exposed!! why not upload the file and encrypt in the server?
That's the part of the design. Anyway we are using AES-256 algorithm for encryption so security is not our issue. What we want to do is directly upload the o/p of algo to the server. Do you have any idea about doing it ?
var req = new XMLHttpRequest();
req.open("POST", url, true);
// set headers and mime-type appropriately
req.setRequestHeader("Content-Length", myBinaryData
Length); req.sendAsBinary(myBinaryData);
i think the bottom line is "if you can get it as a string" just do a normal post. Anyway, I'll be investingating this for im not sure.
ajeet.7
0 Points
6 Posts
Passing file from client side script to server side
Apr 05, 2012 04:54 AM|LINK
This is the simple code to upload a file to azure cloud storage where submitButton_Click uploades the file to blob.
Now i want to encrypt this file on client side using javascript and then upload it to cloud, i wrote a simple javascript that can encrypt the file but i'm not a getting a way to upload the output to cloud
function encrypt() { var reader = new FileReader(); reader.onload = function (e) { var filedata = e.target.result; var encfile = EncryptStr(filedata, document.getElementById("passwd").value, 32); Save(encfile); }; reader.readAsBinaryString(file); }function Save(data) { uriContent = "data:application/octet-stream;base64," + data; document.location.href = uriContent; }this gives me the output which directly gets stored on the local machine, now i want to modify the code so that the output is uploaded directly to the server.
Mauro_net
Contributor
2114 Points
402 Posts
Re: Passing file from client side script to server side
Apr 07, 2012 03:21 AM|LINK
just a retorical question,
why would you encrypt in the client? client code can be easily obtained and your encryption algorithm exposed!! why not upload the file and encrypt in the server?
ajeet.7
0 Points
6 Posts
Re: Passing file from client side script to server side
Apr 07, 2012 06:42 AM|LINK
That's the part of the design. Anyway we are using AES-256 algorithm for encryption so security is not our issue. What we want to do is directly upload the o/p of algo to the server. Do you have any idea about doing it ?
Mauro_net
Contributor
2114 Points
402 Posts
Re: Passing file from client side script to server side
Apr 07, 2012 08:18 PM|LINK
i know aes 256 is ok, but how do you give it the proper encription keys without the user being able to see them?
now, for the answer, you should do binary post ("go'ol multipart")
you can manually build it yourself
http://footle.org/2007/07/31/binary-multipart-posts-in-javascript/
in FF 3.5+ you can use "sendAsBinary"
i think the bottom line is "if you can get it as a string" just do a normal post. Anyway, I'll be investingating this for im not sure.