3

I'm working on EBICS protocol and i want to read a data in an XML File to compare with another file.

I have successfull decode data from base64 using Convert.FromBase64String(OrderData); but now i have a byte array.

To read the content i have to unzip it. I tried to unzip it using Gzip like this example :

static byte[] Decompress(byte[] data)
{
    using (var compressedStream = new MemoryStream(data))
    using (var zipStream = new GZipStream(compressedStream, CompressionMode.Decompress))
    using (var resultStream = new MemoryStream())
    {
        zipStream.CopyTo(resultStream);
        return resultStream.ToArray();
    }
}

But it does not work i have an error message :

the magic number in gzip header is not correct. make sure you are passing in a gzip stream

Now i have no idea how i can unzip it, please help me !

Thanks !

Thomas Rollet
  • 1,573
  • 4
  • 19
  • 33

3 Answers3

1

Try using SharpZipLib. It copes with various compression formats and is free under the GPL license.

As others have pointed out, I suspect you have a zip stream and not gzip. If you check the first 4 bytes in a hex view, ZIP files always start with 0x04034b50 ZIP File Format Wiki whereas GZIP files start with 0x8b1f GZIP File Format Wiki

Paul
  • 1,483
  • 14
  • 32
1

The first four bytes provided by the OP in a comment to another answer: 0x78 0xda 0xe5 0x98 is the start of a zlib stream. It is neither gzip, nor zip, but zlib. You need a ZlibStream, which for some reason Microsoft does not provide. That's fine though, since what Microsoft does provide is buggy.

You should use DotNetZip, which provides ZlibStream, and it works.

rgahan
  • 667
  • 8
  • 17
Mark Adler
  • 101,978
  • 13
  • 118
  • 158
0

I think I finally got it - as usual the problem is not what is in the title. Luckily I've noticed the word EBICS in your post. So, according to EBICS spec the data is first compressed, then encrypted and finally base64 encoded. As you see, after decoding base64 you need first to decrypt the data and then try to unzip it.

UPDATE: If that's not the case, it turns out from the EBICS spec Chapter 16 Appendix: Standards and references that ZIP refers to zlib/deflate format, so all you need to do is to replace GZipStream with the DeflateStream

Ivan Stoev
  • 195,425
  • 15
  • 312
  • 343