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':
- Code: Select all
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
" error. Note, I've tried about 10 different decompress functions I've found online, all do the same:- Code: Select all
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();
baos.close();
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.
Thanks.

