我在下载时遇到加密文件的问题。我正在使用此代码将数据库下载到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文件?
答案 0 :(得分:1)
使用System.Security
FileStream fsInput = new FileStream(sInputFilename,
FileMode.Open,
FileAccess.Read);
FileStream fsEncrypted = new FileStream(sOutputFilename,
FileMode.Create,
FileAccess.Write);
答案 1 :(得分:0)
而不是
StringWriter sw = new StringWriter();
您可以使用 MemoryStream 并将其包装在 CryptoStream 中以加密数据......