Re: IO.Compression and Encryption
- From: "AnikSol" <anisol@xxxxxxxxxxxxxxxx>
- Date: Fri, 17 Nov 2006 23:36:04 +0800
Jon and David,
Thanks for the advise.
"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
news:MPG.1fc6f3572a9b61c798d61e@xxxxxxxxxxxxxxxxxxxxxxx
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
.
- References:
- IO.Compression and Encryption
- From: AnikSol
- Re: IO.Compression and Encryption
- From: Jon Skeet [C# MVP]
- IO.Compression and Encryption
- Prev by Date: RE: Framework files location for compile
- Next by Date: Re: Socket close notification
- Previous by thread: Re: IO.Compression and Encryption
- Next by thread: FileSystemWatcher help!
- Index(es):
Relevant Pages
|