我正在使用XmlWriter创建一个文件,XmlWriter writer = XmlWriter.Create(fileName);它正在创建一个文件然后我还有一个我正在调用的函数, private void EncryptFile(string inputFile, string outputFile)它需要2个字符串输入和outpulfile,最后我有两个文件,一个是加密的,一个不是.我只想要一个加密文件,但是我的加密函数需要输入由XmlWriter创建的inputfile.有没有什么办法可以创建内存流并将其传递给我的函数而不是创建一个输入文件.我的加密功能
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();
}
}
Run Code Online (Sandbox Code Playgroud)