title: DES decryption error "Bad Data" in C# when closing cryptostream
body: <p>I try to decrypt an  encrypted byte array (encrypt with K1 and decrypt with K2). Visual Studio throws an exception "BAD DATA" when it tries to close my crypto stream</p>
  
  <p>here's my code snippet of DES decryption</p>
  
  <pre><code>public Byte[] Decrypt(Byte[] cipherData, Byte[] key, Byte[] iv)
      {
          MemoryStream ms = new MemoryStream();
          DES mDES = DES.Create();
          mDES.Key = key;
          mDES.IV = iv;
          mDES.Padding = PaddingMode.PKCS7;
          CryptoStream cs = new CryptoStream(ms, mDES.CreateDecryptor(), CryptoStreamMode.Write);
          cs.Write(cipherData, 0, cipherData.Length);
          cs.Close();
          Byte[] decryptedData = ms.ToArray();
          return decryptedData;
      }
  </code></pre>
  
  <p>the initial vector is the same as encryption. I don't know why this error occurred. </p>
  
  <p><em><strong>Added:</em></strong>
  As recommended by Greg B, I post here my code snippet of encryption. The output of encryption is the input of decryption (two different keys)</p>
  
  <pre><code>        public Byte[] Decrypt(Byte[] cipherData, Byte[] key, Byte[] iv)
      {
          MemoryStream ms = new MemoryStream();
          DES mDES = DES.Create();
          mDES.Key = key;
          mDES.IV = iv;
          mDES.Padding = PaddingMode.PKCS7;
          CryptoStream cs = new CryptoStream(ms, mDES.CreateDecryptor(), CryptoStreamMode.Write);
          cs.Write(cipherData, 0, cipherData.Length);
          cs.Close();
          Byte[] decryptedData = ms.ToArray();
          return decryptedData;
      }
  </code></pre>