title: C# "Bad Data" exception when decrypting encrypted file
body: <p>Hey I'm very new to encryption and decryption, or even the c# language to be honest. Basically, I have a tcp chat server that "saves" logs and encrypts the text file. This is how I encrypt (based from the MSDN sample):</p>
  
  <pre><code>public static void EncryptFile(string strInputFileName, string strOutputFileName, string strKey)
  {
      FileStream fsIn = new FileStream(strInputFileName, FileMode.Open, FileAccess.Read);
      FileStream fsOut = new FileStream(strOutputFileName, FileMode.Create, FileAccess.Write);
  
      DESCryptoServiceProvider des = new DESCryptoServiceProvider();
      des.Key = ASCIIEncoding.ASCII.GetBytes(strKey);
      des.IV = ASCIIEncoding.ASCII.GetBytes(strKey);
  
  
      ICryptoTransform desencrypt = des.CreateEncryptor();
      CryptoStream cryptostream = new CryptoStream(fsOut, desencrypt, CryptoStreamMode.Write);
  
      byte[] byteArrayInput = new byte[fsIn.Length - 1];
      fsIn.Read(byteArrayInput, 0, byteArrayInput.Length);
      cryptostream.Write(byteArrayInput, 0, byteArrayInput.Length);
  
      fsIn.Close();
      fsOut.Close();
  }
  </code></pre>
  
  <p>The method success fully encrypts files. This is my decrypt method:</p>
  
  <pre><code>public static void DecryptFile(string strInputFileName, string strOutputFileName, string strKey)
  {
      DESCryptoServiceProvider des = new DESCryptoServiceProvider();
      des.Key = ASCIIEncoding.ASCII.GetBytes(strKey);
      des.IV = ASCIIEncoding.ASCII.GetBytes(strKey);
  
      byte[] te = new byte[1024];
      FileStream fsRead = new FileStream(strInputFileName, FileMode.Open, FileAccess.Read);
      ICryptoTransform desdecrypt = des.CreateDecryptor();          
  
      CryptoStream cryptostream = new CryptoStream(fsRead, desdecrypt, CryptoStreamMode.Read);
      StreamWriter fsDecrypted = new StreamWriter(strOutputFileName);            
  
      fsDecrypted.Write(new StreamReader(cryptostream).ReadToEnd());//This is where the "Bad Data" occurs.
      fsDecrypted.Flush();
      fsDecrypted.Close();
      fsRead.Close();
  }
  </code></pre>
  
  <p>And when I inspect the cryptostream object, it says that it has thrown an exception, "Stream does not support seeking".</p>
  
  <p>Any help would be greatly appreciated!</p>