Encryption mvc5中的文件加密
在mvc5中的grid view下载文件后,我立即加密该文件,但我得到的是0字节的加密文件,当我重新下载该文件时,我得到的是正确的加密文件。有人能告诉我代码有什么问题吗?或者下载后我必须延迟加密功能一段时间使用吗系统安全Encryption mvc5中的文件加密,encryption,cryptography,asp.net-mvc-5,filestream,Encryption,Cryptography,Asp.net Mvc 5,Filestream,在mvc5中的grid view下载文件后,我立即加密该文件,但我得到的是0字节的加密文件,当我重新下载该文件时,我得到的是正确的加密文件。有人能告诉我代码有什么问题吗?或者下载后我必须延迟加密功能一段时间使用吗系统安全 var graphids = from o in db.OfflineCarts join i in db.Graphs on o.ItemId equals i.ItemUserID
var graphids = from o in db.OfflineCarts
join i in db.Graphs on o.ItemId equals i.ItemUserID
select i;
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);
gv.RenderControl(htw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
Encryption();
public void Encryption()
{
string password = @"myKey123"; // Your Key Here
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
string cryptFile = "/Users/Neeraj/Downloads/UserFilesEncrypt.xls";
FileStream fsCrypt = new FileStream(cryptFile, FileMode.CreateNew);
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream rs = new CryptoStream(fsCrypt,
RMCrypto.CreateEncryptor(key, key),
CryptoStreamMode.Read);
CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateEncryptor(key, key),
CryptoStreamMode.Write);
string inputFile = "/Users/Neeraj/Downloads/GraphTable.xls";
FileStream fsIn = new FileStream(inputFile, FileMode.Open);
int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);
fsIn.Close();
cs.Close();
fsCrypt.Close();
}
FileStream fsInput = new FileStream(sInputFilename,
FileMode.Open,
FileAccess.Read);
FileStream fsEncrypted = new FileStream(sOutputFilename,
FileMode.Create,
FileAccess.Write);