簡體   English   中英

下載時如何加密文件

[英]how to encrypt a file While downloading

我在下載時加密文件時遇到問題。我正在使用此代碼將數據庫下載到excel文件中

GridView gv = new GridView();
                gv.DataSource = graphids.ToList();
                gv.DataBind();
                Response.ClearContent();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment; filename=GraphTable.xls");
                Response.ContentType = "application/ms-excel";
                Response.Charset = "";
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
                Response.Output.Write(sw.ToString());
                Response.Flush();
                Response.End();

現在,此代碼文件自動下載到我的PC的下載文件夾之后,現在我要在下載之前加密此xls文件嗎?

使用System.Security

FileStream fsInput = new FileStream(sInputFilename, 
                    FileMode.Open, 
                    FileAccess.Read);

    FileStream fsEncrypted = new FileStream(sOutputFilename, 
                    FileMode.Create, 
                    FileAccess.Write);

代替

StringWriter sw = new StringWriter();

您可以使用MemoryStream並將其包裝在CryptoStream中以加密數據...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM