tags:

views:

34

answers:

1

Well, I'm trying to gzdeflate my code to perform some very low level encryption for distribution, to use with eval(gzinflate('deflated_code'));

However whenever I try to inflate the deflated string, it outputs an error.

For example:

echo(gzdeflate('test')); outputs +I-.�

But when I try to echo(gzinflate('+I-.�')); it only outputs Warning: gzinflate() [function.gzinflate]: data error

Is there something I'm missing? Why is it outputting this error rather than test?

+2  A: 

The output of

$s = gzdeflate('test');
for ($i=0; $i<strlen($s); $i++) {
  printf("%02X ", ord($s[$i]));
}

is 2B 49 2D 2E 01 00. The last two bytes 01 00 are in this case the tricky part.
You used echo to print the result "string". What was the output medium?
When I copy the string +I-.� via ultraedit into the script the output is 2B 49 2D 2E 3F. A different result and the cause for gzinflate() to bail out.

If you really have to display the data in a medium that cannot show all possible "characters" in the result of gzdeflate() you have to encode the result in a way that either those unprintable characters are avoided or encoded in a suitable form for that medium, e.g. via base64_encode().

VolkerK
Not sure what you mean by medium? And how can I get the correct I guess, 'printable' string, so that i can inflate it properly? Also, I will be using base64 as well, but I also want this for additional "encryption" if I can call it that.
Rob
So, `echo(base64_encode(gzdeflate('string')));`?
Rob
VolkerK
Well I've seen it used before (here - http://stackoverflow.com/questions/2722973/how-can-i-gzinflate-and-save-the-inflated-data-without-running-it-found-what-i) and so I need to know how I can properly input the string necessary to inflate it correctly, like they did there.
Rob
Nevermind. reversed the position of base64_encode and gzdeflate, and it worked. Thanks for the help :)
Rob