473,322 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

CryptoStream - GZipStream, Possible???

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
2 4953
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: weixiang | last post by:
Hi, I want to use DES and CryptoStream to serialize a encrypted stream to a file with a header "CRYPT". And I wrote these code: To store: FileStream fileStream = new FileStream(fileName,...
7
by: semedao | last post by:
Hi, I am using cryptostream on both sides on tcp connection that pass data. I am also use asyc socket , so , the data that recieved in the callback method not always have the length of the buffer...
1
by: sedwick | last post by:
I'm using .NET 2.0.50727 in VS 2005 Pro, ENU Service Pack 1 (KB926601). I've been experimenting with the System.IO.Compression classes GZipStream and DeflateStream, and I found it interesting to...
4
by: Arnie | last post by:
Folks, The GZipStream class in .NET is throwing an exception during an OS unseal/power up (first boot experience). The .NET system is fully up as other apps seem to run fine.
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.