CryptoStream - GZipStream, Possible???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?TWFydGluIE1hZHJlemE=?=

    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
  • Marc Gravell

    #2
    Re: CryptoStream - GZipStream, Possible???

    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

    Comment

    • Marc Gravell

      #3
      Re: CryptoStream - GZipStream, Possible???

      Like so:

      Rijndael r = Rijndael.Create ();
      Console.WriteLi ne("IV: " + r.IV);
      Console.WriteLi ne("Key: " + r.Key);
      using(FileStrea m raw = File.Create("fo o.bar"))
      using(CryptoStr eam cs = new CryptoStream(ra w,
      r.CreateEncrypt or(), CryptoStreamMod e.Write))
      using(GZipStrea m gzip = new GZipStream(cs,
      CompressionMode .Compress))
      using(StreamWri ter writer = new StreamWriter(gz ip)) {
      for(int i = 0 ; i < 100 ; i++) {
      writer.WriteLin e("Line {0} - blah blah blah blah",
      i);
      }
      writer.Close();
      gzip.Close();
      cs.Close();
      raw.Close();
      }

      Console.WriteLi ne("Size: " + new
      FileInfo("foo.b ar").Length);

      using(FileStrea m raw = File.OpenRead(" foo.bar"))
      using(CryptoStr eam cs = new CryptoStream(ra w,
      r.CreateDecrypt or(), CryptoStreamMod e.Read))
      using(GZipStrea m gzip = new GZipStream(cs,
      CompressionMode .Decompress))
      using (StreamReader reader = new StreamReader(gz ip))
      {
      string line;
      while((line = reader.ReadLine ()) != null) {
      Console.WriteLi ne(line);
      }
      }

      Comment

      Working...