File data changed after encrypting then decrypting
<p>I encrypted a file using DES then After decrypting it successfully at the server and using </p>

<pre><code>System.IO.File.WriteAllBytes(@"c:\test\" + fileName, decryptedFile);
</code></pre>

<p>method the file data changed a little it the text is "Encrypting and Decrypting usind DES blah blah blah blah"
the text in the end file after decrypting is " k$nlng and Decrypting usind DES blah blah blah blah"
and i also tried this:</p>

<pre><code>using (BinaryWriter binWriter =
                        new BinaryWriter(File.Open(@"C:\Test\" + fileName, FileMode.Create)))
                {
                    binWriter.Write(decryptedFile);
                }
</code></pre>

<p>the text still not the same
encrypting by :</p>

<pre><code>public byte [] DESEncrypt(byte [] fileBytes)
    {
        CryptoStreamMode mode = CryptoStreamMode.Write;

        // Set up streams and encrypt
        MemoryStream memStream = new MemoryStream();
        CryptoStream cryptoStream = new CryptoStream(memStream, 
            cryptoProvider.CreateEncryptor(cryptoProvider.Key, cryptoProvider.Key), mode);
        cryptoStream.Write(fileBytes, 0, fileBytes.Length);
        cryptoStream.FlushFinalBlock();

        // Read the encrypted message from the memory stream
        byte[] encryptedMessageBytes = new byte[memStream.Length];
        memStream.Position = 0;
        memStream.Read(encryptedMessageBytes, 0, encryptedMessageBytes.Length);
        MessageBox.Show("encrypted DES");
        return encryptedMessageBytes;
    }
</code></pre>

<p>decrypting by:</p>

<pre><code>static public byte[] DESdecrypt(byte [] fileBytes)
    {

        ICryptoTransform decryptor = cryptoProvider.CreateDecryptor();
        byte[] originalAgain = decryptor.TransformFinalBlock(fileBytes, 0, fileBytes.Length);

        return originalAgain;
    }
</code></pre>

<p>Thanks</p>
