Search code examples
gzipcrypto++

Crypto++ library gzip issue


I am having an issue with the GZIP class of the Crypto++ library. I am working on a server client app. The client app is written in C++. I encrypt data using the GZIP class as follows:

#include <gzip.h>

Gzip zipper(1);    // 1 is fast, 9 is slow

zipper.Put(pData,dwLen);
zipper.Close();

byte* pCompressed = new byte[zipper.MaxRetrieveable()];
zipper.Get(pCompressed,zipper.MaxRetrieveable());

The data is hex encoded and then transferred to the PYTHON utilize which decodes and attempts to decompress these GZIP streams as follows:

import gzip
import StringIO
fio = StringIO.StringIO(gzip_data)
f = gzip.GzipFile(fileobj=fio)
f.read()
'test'
f.close()

And I have also tried the following as:

fh = gzip.open('abc.gz', 'rb')
cdata = fh.read()
fh.close()

This seems simple enough, but it is not working correctly and gives me errors during the decompression process on the PYTHON end. Is there a separate way to decompress streams vs actual files utilizing the PYTHON module class?

If anyone else has had this issue, any assistance would be greatly appreciated.

UPDATE

Thank you for your reply jww. Just FYI, I got this to work today by decompressing the received stream, from the C++ software utilizing the CryptoPP library, as follows within the PYTHON client:

compressedstream = StringIO.StringIO(data2)
gzipper = gzip.GzipFile(fileobj=compressedstream)
f = gzipper.read()

I am not sure exactly why this works. It appears as though you must process/decompress gzip streams and gzip files differently. In any case, the stream decompression method using the PYTHON gzip.GzipFile method works very nicely.


Solution

  • UPDATE

    Thank you for your reply jww. Just FYI, I got this to work today by decompressing the received stream, from the C++ software utilizing the CryptoPP library, as follows within the PYTHON client:

    compressedstream = StringIO.StringIO(data2)
    gzipper = gzip.GzipFile(fileobj=compressedstream)
    f = gzipper.read()
    

    I am not sure exactly why this works. It appears as though you must process/decompress gzip streams and gzip files differently. In any case, the stream decompression method using the PYTHON gzip.GzipFile method works very nicely.