0
我有一個解密的XML字符串,通過電線發送到我的代碼所在的接收框。現在,我想將這個XML字符串寫入一個XML文件。將序列化的XML字符串寫入XML文件
下面是我的代碼調用來生成這個XML字符串的解密方法...也許這需要改變?
[更新]:我的問題是,我看不到一種方法來從XML字符串寫入/創建XML文件...我可以看到使用流,URL的示例,但不在這裏幫不了我。
protected string DecryptForm(byte[] encryptedString, byte[] key, byte[] vector)
{
rijndael = new RijndaelManaged();
rijndael.Mode = CipherMode.CBC;
// Create a decryptor to perform the stream transform
ICryptoTransform decryptor = rijndael.CreateDecryptor(key, vector);
string plainText = null;
try
{
//Create the streams used for decryption
using (MemoryStream msStream = new MemoryStream(encryptedString))
{
using (CryptoStream csStream = new CryptoStream(msStream,
decryptor, CryptoStreamMode.Read))
{
using (StreamReader readerStream = new StreamReader(csStream))
{
// Read the decrypted bytes from the decrypting stream
plainText = readerStream.ReadToEnd();
}
}
}
finally
{
// Clear the RijndaelManaged object
if(rijndael != null)
rijndael.Clear();
}
// Return the decrypted string
return plainText;
}
}
有什麼問題嗎?你有什麼問題? – DaveE 2010-07-29 23:44:07
我想不出從XML字符串創建XML文件的簡單方法。我可以看到如何從一個流,一個URL等來完成它。 – IrishChieftain 2010-07-29 23:50:09
請參閱[ 如何將XML字符串寫入文件? ](http://stackoverflow.com/questions/590881/how-do-i-write-an-xml-string-to-a-file/590958#590958)。 – 2010-07-29 23:53:19