Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8668677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:16:23+00:00 2026-06-12T18:16:23+00:00

This is probably a very localized question not useful for the rest of the

  • 0

This is probably a very localized question not useful for the rest of the community but hopefully someone can help me.

What I know

I have a base64 encoded ZIP, in a string, inside an XML element.

The file looks like this:

<Document>
   <Content vesion="1"><!-- BASE64 STRING ---></Content>
</Document>

What I want to do

Decode the string, and then unzip it.

What I’ve tries so far (and failed)

  • Decoded the base64 string and put it in a file with a zip extension

    public string DecodeFrom64(string encodedData)
    {
    
        byte[] encodedDataAsBytes
    
            = System.Convert.FromBase64String(encodedData);
    
        string returnValue =
    
           System.Text.Encoding.Unicode.GetString(encodedDataAsBytes);
    
        return returnValue;
    
    }
    
  • Tried to unzip the string with the function:

    public static string DecompressString(string compressedText)
    {
        byte[] gZipBuffer = Convert.FromBase64String(compressedText);
        using (var memoryStream = new MemoryStream())
        {
            int dataLength = BitConverter.ToInt32(gZipBuffer, 0);
            memoryStream.Write(gZipBuffer, 4, gZipBuffer.Length - 4);
    
            var buffer = new byte[dataLength];
    
            memoryStream.Position = 0;
            using (var gZipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
            {
                gZipStream.Read(buffer, 0, buffer.Length);
            }
    
            return Encoding.UTF8.GetString(buffer);
        }
    }
    

Got the error:

The magic number in GZip header is not correct. Make sure you are passing in a GZip stream…

  • Tried to decompress the string with the function:

    public static string UnZipStr(string compressedText)
    {
        byte[] input = Convert.FromBase64String(compressedText);
        using (MemoryStream inputStream = new MemoryStream(input))
        {
            using (DeflateStream gzip =
              new DeflateStream(inputStream, CompressionMode.Decompress))
            {
                using (StreamReader reader =
                  new StreamReader(gzip, System.Text.Encoding.UTF8))
                {
                    return reader.ReadToEnd();
                }
            }
        }
    }
    

Got the error:

Block length does not match with its complement…

I sent a mail to the guys that are sending this XML data to my customer, but the problem is that they are very slow to respond (3-4 weeks).

So I am hoping someone can point me in the right direction.

I can not append files to the question, so if someone wants have a look at it I can send a mail or something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:16:24+00:00Added an answer on June 12, 2026 at 6:16 pm

    As Harold already pointed out in the comments, this is all wrong. In your last comment (Jester) you clarified that the zip file was first converted to a string, and then that string got converted to a base64 string. As this absolutely makes no sense (why should you do that), I imagine that you got something wrong there and really mean that the file got converted to a base64 string. This is best practice for email for example, and I’ve recently been doing that to transfer files via XML in XMPP. My guess would be that…

    byte[] file = System.Convert.FromBase64String(encodedData);
    File.WriteAllBytes(directoryToWriteTo+filename+".zip", file);
    

    … creates the file you’re looking for. byte[] here already IS a zip file. As zip files can be messy to deal with (as you didn’t really say what’s in there), I would recommend saving these bytes to a file and try to open it with a zip-software like WinRar. If this worked and you can get the file contents out of the zip file, you could ask another question how to the the contents. I would also recommend using SharpZipLib.dll, because it’s really the only solution I got working in reasonable time so far.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a very simple question so please forgive my ignorance, but can
I know this is probably very elementary, but I can't seem to figure it
This is probably a very basic question, but I could not get my way
This is probably very easy to do but for some reason I can't seem
OK, this is probably very basic, but I can't find the problem. I'm trying
This is probably a very simple question but I'm a little confused how this
This is probably very basic, but it's giving me a headache, and I'm not
This is probably very easy, but I just can't figure out how to solve
I'm sorry for this ( probably very ) noob question, but i've been asked
Okay, this is probably very simple but, I have the below checks (not at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.