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 !

7
  • 1
    Can you show how you are compressing the data? Commented Oct 14, 2015 at 7:29
  • I haven't compress data, i want to read the data compressed Commented Oct 14, 2015 at 7:33
  • Are you sure your OrderData has been compressed with GZipStream before being encoded to base64 and written to XML file? Commented Oct 14, 2015 at 7:41
  • It's not encoded with GzipStream but there is the only one is available in my .NET Framework Commented Oct 14, 2015 at 7:43
  • Then how it has been encoded? Commented Oct 14, 2015 at 7:44

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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

3 Comments

It's not a File juste byte array
list the first 4 bytes please.
converting your first number 120218229152217 to hex gives 0x72A6275 which I am not familiar with. Your edit is also an unfamiliar sequence.
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

1 Comment

In HIA request, orders in EBICS message are not encrypted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.