【发布时间】:2016-05-25 05:22:42
【问题描述】:
public Stream DecryptFile(string inputFile)//, string outputFile)
{
{
string password = @"mykey"; // Your Key Here
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateDecryptor(key, key),
CryptoStreamMode.Read);
StreamReader sr = new StreamReader(cs);
Stream s = sr.BaseStream;
//sr.Close();
//fsCrypt.Close();
return s;
}
}
在此代码中存在流未正确关闭的问题。 如果我在返回值之前关闭它,则会引发错误。
【问题讨论】:
-
读取文件后它不允许我替换它,因为流是打开的。
-
你需要在返回 s 之前关闭 fsCrypt
-
如果我在它显示找不到表 0 之前关闭它。
标签: c# filestream