protected void Button1_Click(object sender, EventArgs e) { string filename = DropDownList1.SelectedItem.Value; string filePath = Path.Combine(Server.MapPath("~/cloudfiles"), filename); // key for decryption byte[] Key = Encoding.UTF8.GetBytes("asdf!@#$1234ASDF"); //UnicodeEncoding ue = new UnicodeEncoding(); FileStream fs = new FileStream(filePath, FileMode.Open); AesManaged rmCryp = new AesManaged(); CryptoStream cs = new CryptoStream(fs, rmCryp.CreateDecryptor(Key, Key), CryptoStreamMode.Read); try { // Decrypt & Download Here Response.Clear(); Response.ContentType = "application/octet-stream"; // Response.AddHeader("Content-Disposition","attachment; filename=" + Path.GetFileName(filePath) + Path.GetExtension(filePath)); Response.AddHeader("Content-Disposition", "attachment; filename=myfile" + Path.GetExtension(filePath)); int data; while ((data = cs.ReadByte()) != -1) { Response.OutputStream.WriteByte((byte)data); Response.Flush(); } cs.Close(); fs.Close(); } catch (Exception ex) { Response.Write(ex.Message); } finally { cs.Close(); fs.Close(); } }
Hi all For my research work im doing about a access control model and it uses AES symmetric key encryption for encrypting the file while uploading and decryption while downloading.As im a newbie i have used a available algorithm and when im downloading file it is larger than original file and it has a content of the web page also.As an example if i encrypt text file when im downloading it embedded with web page content.can any one help me with that ? here is my code for file decryption.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)