Hi.

I have a problem that I've been trying to solve over the last couple of days and I have had no success whatsoever. Basically, I'm RC4 encrypting a short string in a C program, which creates a connection to an url and sends the encrypted string as a parameter, which I'm "_GET-ing" with my PHP script. The encrypted string is converted from binary to hex before it is inserted into the url. That works fine. I can encrypt and decrypt the code on my computer just fine, even if I'm using different implementations/tools. Decrypting the code in the PHP script, however, just gives me a mess. The hex codes also don't match if if encode the very same plain string within the PHP script and compare the results with what I get from my c program. I'm using the Crypt_RC4 class package from PEAR. I scanned over the code and it seems to be using the very same implementation that I use in my C program. I'm starting to think that PHP encodes strings in a different way than my C program does. I'm using just plain vanilla UTF8 8-bit signed char array c-strings. I'm aware that RC4 is a stream key encryption mechanism, so that's not the problem here.

Any help is greatly appreciated. I really don't know what else I can try to get this to work. It is frustrating because it seems to be such a simple task.

Thank you very much.

Florian

Hi.

I have a problem that I've been trying to solve over the last couple of days and I have had no success whatsoever. Basically, I'm RC4 encrypting a short string in a C program, which creates a connection to an url and sends the encrypted string as a parameter, which I'm "_GET-ing" with my PHP script. The encrypted string is converted from binary to hex before it is inserted into the url. That works fine. I can encrypt and decrypt the code on my computer just fine, even if I'm using different implementations/tools. Decrypting the code in the PHP script, however, just gives me a mess. The hex codes also don't match if if encode the very same plain string within the PHP script and compare the results with what I get from my c program. I'm using the Crypt_RC4 class package from PEAR. I scanned over the code and it seems to be using the very same implementation that I use in my C program. I'm starting to think that PHP encodes strings in a different way than my C program does. I'm using just plain vanilla UTF8 8-bit signed char array c-strings. I'm aware that RC4 is a stream key encryption mechanism, so that's not the problem here.

Any help is greatly appreciated. I really don't know what else I can try to get this to work. It is frustrating because it seems to be such a simple task.

Thank you very much.

Florian

Which version of PHP are you using?

The hex codes also don't match if if encode the very same plain string within the PHP script and compare the results with what I get from my c program.

Sounds like the problem right there.

Most of PHP's string functions are not multi-byte aware, so they will mangle character encodings like UTF-8.

http://www.phpwact.org/php/i18n/utf-8

Can you rule out the encoding?

ie: do the hex functions in PHP and C give the same result with ASCII?

This article has been dead for over six months. Start a new discussion instead.