Re: IO.Compression and Encryption
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Thu, 16 Nov 2006 22:15:23 -0000
AnikSol <anisol@xxxxxxxxxxxxxxxx> wrote:
<snip>
Can anyone point out what are we doing wrong? If we just compress and
decompress the file using the same code, its perfect. If we encrypt and
decrypt the file using the same class, its perfect. But if we do the
combination of compression and encryption, the file is totally messed up.
Any reasons?
Clearly the encryption/decryption is *not* valid on its own - that much
is clear from the fact that you can't decrypt the encrypted data and
get the same size.
By the looks of it, the problem is that you're using a StreamReader on
the encrypted file. StreamReaders deal with *text*, not arbitrary
binary data - and compressed data is effectively arbitrary binary data.
I'm sure you'll find that the encryption/decryption fails on its own if
you try to encrypt/decrypt a binary file like an image.
You should write the decrypted data by reading a chunk from the
decryption stream, writing it to the file stream, then reading a chunk,
etc, until you've read everything.
See http://www.pobox.com/~skeet/csharp/readbinary.html for more on
this.
At a quick glance, it looks like your compression is assuming text data
as well: it shouldn't. Compression and encryption should generally work
on just binary data. That way *any* file should come through correctly,
whether it's text or not.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: IO.Compression and Encryption
- From: AnikSol
- Re: IO.Compression and Encryption
- References:
- IO.Compression and Encryption
- From: AnikSol
- IO.Compression and Encryption
- Prev by Date: Re: IO.Compression and Encryption
- Next by Date: Re: combobox find item by value
- Previous by thread: Re: IO.Compression and Encryption
- Next by thread: Re: IO.Compression and Encryption
- Index(es):
Relevant Pages
|