加密HttpPostedFileBase

时间:2014-01-15 20:02:13

标签: c# asp.net-mvc

我正在开发一个asp mvc#应用程序。我想要加密HttpPostedFileBase(下面代码中的file是我要加密的HttpPostedFileBase

void Upload(string target, HttpPostedFileBase file)
{
FullPath dest = ParsePath(target);
FileInfo path = new FileInfo(Path.Combine(dest.Directory.FullName, Path.GetFileName(file.FileName)));

//file.SaveAs(path.FullName);

MemoryStream _MemoryStream = new MemoryStream();
file.InputStream.CopyTo(_MemoryStream);

DESCryptoServiceProvider cryptic = new DESCryptoServiceProvider();

cryptic.Key = ASCIIEncoding.ASCII.GetBytes("ABCDEFGH");
cryptic.IV = ASCIIEncoding.ASCII.GetBytes("ABCDEFGH");

CryptoStream crStream = new CryptoStream(_MemoryStream, cryptic.CreateEncryptor(), CryptoStreamMode.Write);
//Here I want to save my crypted stream to the path
//....
}

1 个答案:

答案 0 :(得分:0)

    CryptoStream crStream = new CryptoStream(_MemoryStream, cryptic.CreateEncryptor(), CryptoStreamMode.Write);
    using (var output = new FileStream(path.FullName, FileMode.Create, FileAccess.Write))
    {
        crStream.CopyTo(output);
    }