views:

56

answers:

1

I have a decrypted XML string which was sent over the wire to the receiving box where my code resides. Now, I want to write this XML string to an XML file.

Here's the Decrypt method which my code calls to generate this XML string... maybe this needs to be changed?

[Update]: My problem is that I can't see a way to write/create an XML file from a string of XML... I can see samples using a stream, a URL, but that doesn't help me here.

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;
    }

}

+1  A: 
xmlDoc = new XmlDocument();
xmlDoc.LoadXML(MyXMLString);
xmlDoc.Save(MyFilePath)
SteveCav
Thanks Steve :-)
IrishChieftain