By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,218 Members | 1,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,218 IT Pros & Developers. It's quick & easy.

CryptoStream - GZipStream, Possible???

P: n/a
Hi,

i've got problems with CryptoStream and GZipStream. Someone tried that? Or
got any idea why this wont work?

i tried every combination, first i used CryptoStream, after that GZipStream.
Or first i create a file with GZipStream and crypt that file. But become back
the orginal is impossible...

I hope anyone got an idea how this could work.

Thanks

Martin
Oct 15 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
They should work fine together... just make sure you gzip first, then
encrypt (encrypted data doesn't compress). What error (etc) did you
see?

Marc
Oct 15 '08 #2

P: n/a
Like so:

Rijndael r = Rijndael.Create();
Console.WriteLine("IV: " + r.IV);
Console.WriteLine("Key: " + r.Key);
using(FileStream raw = File.Create("foo.bar"))
using(CryptoStream cs = new CryptoStream(raw,
r.CreateEncryptor(), CryptoStreamMode.Write))
using(GZipStream gzip = new GZipStream(cs,
CompressionMode.Compress))
using(StreamWriter writer = new StreamWriter(gzip)) {
for(int i = 0 ; i < 100 ; i++) {
writer.WriteLine("Line {0} - blah blah blah blah",
i);
}
writer.Close();
gzip.Close();
cs.Close();
raw.Close();
}

Console.WriteLine("Size: " + new
FileInfo("foo.bar").Length);

using(FileStream raw = File.OpenRead("foo.bar"))
using(CryptoStream cs = new CryptoStream(raw,
r.CreateDecryptor(), CryptoStreamMode.Read))
using(GZipStream gzip = new GZipStream(cs,
CompressionMode.Decompress))
using (StreamReader reader = new StreamReader(gzip))
{
string line;
while((line = reader.ReadLine()) != null) {
Console.WriteLine(line);
}
}
Oct 15 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.