PC Review


Reply
Thread Tools Rate Thread

CryptoStream - GZipStream, Possible???

 
 
Martin Madreza
Guest
Posts: n/a
 
      15th Oct 2008
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
 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      15th Oct 2008
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
 
Reply With Quote
 
Marc Gravell
Guest
Posts: n/a
 
      15th Oct 2008
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);
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using CryptoStream jp2msft Microsoft C# .NET 14 7th Dec 2008 01:43 AM
Problems with CryptoStream karthy84@gmail.com Microsoft C# .NET 2 15th Nov 2007 06:52 PM
CryptoStream =?Utf-8?B?RnJlZCBIZXJyaW5n?= Microsoft Dot NET Framework Forms 1 6th Jan 2005 08:11 PM
Cryptostream truncation Matt Microsoft Dot NET Framework 2 5th Aug 2003 06:16 PM
CryptoStream? weixiang Microsoft C# .NET 5 25th Jul 2003 12:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:36 AM.