7
我使用XmlWriter創建一個文件,XmlWriter writer = XmlWriter.Create(fileName);
它創建一個文件,然後我有一個更多的功能,我打電話private void EncryptFile(string inputFile, string outputFile)
這需要2個字符串輸入和outpulfile,最後我有兩個文件一個是加密的,另一個不是。我只想要一個加密文件,但是我的加密函數採用由XmlWriter創建的inputfile。有什麼辦法可以創建內存流並將其傳遞到我的函數中,而不是創建輸入文件。 我的加密功能XML writer和Memory Stream c#
private void EncryptFile (string inputFile, string outputFile)
string password = @"fdds"; // Your Key Here
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
string cryptFile = outputFile;
FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fsCrypt,RMCrypto.CreateEncryptor(key,key),CryptoStreamMode.Write);
FileStream fsIn = new FileStream(inputFile, FileMode.Open);
int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);
cs.FlushFinalBlock();
fsIn.Close();
cs.Close();
fsCrypt.Close();
}
}
writer.Flush()是我失蹤的。謝謝。 – granadaCoder