刚刚在代码中出现了一些错误,表明该文件正在被使用。我需要实现的是在文件中添加第一部分加密数据,然后在同一文件中添加第二部分 evcrypted 数据。该文件需要稍后解密。我对这个领域很陌生。非常感谢。
Class3 cs3;
StreamWriter sWriter;
private void Add_text_Part_One()
{
Rijndael RijndaelAlg = Rijndael.Create();
// Create a string to encrypt.
string sData = "Here is some data to encrypt.";
string FileName = @"C:\CText.txt";
cs3 = new Class3(sData, FileName, RijndaelAlg.Key, RijndaelAlg.IV);
sWriter = new StreamWriter(cs3.getCS());
sWriter.WriteLine(sData);
sWriter.Close();
}
private void Add_text_Part_Two()
{
string sData = "Here is some more data to encrypt.";
sWriter.WriteLine(sData);
sWriter.Close();
}
class Class3
{
FileStream fStream;
Rijndael RijndaelAlg;
CryptoStream cStream;
public Class3(String Data, String FileName, byte[] Key, byte[] IV)
{
fStream = File.Open(FileName, FileMode.Append);
RijndaelAlg = Rijndael.Create();
cStream = new CryptoStream(fStream, RijndaelAlg.CreateEncryptor(Key, IV), CryptoStreamMode.Write);
}
public CryptoStream getCS()
{
return cStream;
}
public string getRes()
{
StreamReader sReader = new StreamReader(cStream);
string val = null;
val = sReader.ReadLine();
return val;
}