1. You want that $100.00 in your pocket or an Amazon Fire TV don't you? Well here's the deal. With our new updated look we are in desperate need of an updated logo. The 'old' one has certainly served us well, but it's time. Find all the details here: bit.ly/1q0k6Wa
  2. DroidForums.net is currently undergoing a major software upgrade. If you are experiencing any problems logging in please: Contact Us

Decompress a GZIP "string" compressed in .NET

Discussion in 'Android App Developers' started by AndPig, Sep 15, 2012.

  1. AndPig

    AndPig New Member

    Sep 15, 2012
    Likes Received:
    Trophy Points:
    Hallo - I'm new here and also fairly new to Android development, hopefully someone can help me with this issue.

    I've got an issue trying to decompress something that was compressed in VB.NET using Gzip.

    In .NET the following occurs to an XML file:

    - The file is compressed using Gzip
    - The result is encrypted using Triple3DES
    - The result is saved to a file

    In Android, I've got the 3DES decryption working fine, which when I open a file where I only encrypted in .NET, returns the XML that was originally encrypted.

    The problem is trying to get the decompress function working also. I think the issue relates to the compressed data being binary and not a string, but only a hunch.

    This is my decrypt function - I use fileToByteArray to convert the file on the SD card to pass in as 'message':

    public static String decrypt(byte[] message) throws Exception {
        	final byte[] keyBytes = "1232223423513131".getBytes();
            final SecretKey key = new SecretKeySpec(keyBytes, "DESede");
            final IvParameterSpec iv = new IvParameterSpec("12345678".getBytes());
            final Cipher decipher = Cipher.getInstance("DESede/CBC/PKCS7Padding");
            decipher.init(Cipher.DECRYPT_MODE, key, iv);
            final byte[] plainText = decipher.doFinal(message);
            return new String(plainText);
    The above works fine when I open a file that was only encrypted in .NET. But if I try to decompress the resultant string with the below, I get an "Unknown format (magic number 8)" error. Note, I've tried about 10 different decompress functions I've found online, all do the same:

    public static String decompress(String gzipString) throws IOException {
    	    int size = 0;
    	    byte[] gzipBuff = gzipString.getBytes();
    	    ByteArrayInputStream memstream = new ByteArrayInputStream(gzipBuff, 4,
    	            gzipBuff.length - 4);
    	    GZIPInputStream gzin = new GZIPInputStream(memstream);
    	    final int buffSize = 8192;
    	    byte[] tempBuffer = new byte[buffSize];
    	    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    	    while ((size = gzin.read(tempBuffer, 0, buffSize)) != -1) {
    	        baos.write(tempBuffer, 0, size);
    	    byte[] buffer = baos.toByteArray();
    	    return new String(buffer, "UTF-8");
    The gzipString parameter value passed in to the decompress function looks like binary would as a string.. it contains lots of odd characters that won't paste into here. Not sure if that helps!

    Can anyone suggest what might be wrong, or a good path for investigating this further?

    Any help appreciated.

Search tags for this page
.net gzip string
.net gzip a string
android and vb string compression
android compress string
android decode gzip
compress string vb.net
decompress gzip string vb.net

gzip string online


vb.net compress string

vb.net compress xml string
vb.net gzip code
vb.net gzipstream decompress unknown buffer size