views:

372

answers:

3

Hello, I have been searching and cant find a consistent solution to my problem :

I want to encrypt something in C# and decrypt it in PHP but also be able to encrypt in PHP and decrypt in C#, using the same key on both ends.

All the solutions I found dont seem to work both ways, most of them only work on one language and then fail on the other, either by decrypting wrong or by blowing up the offsets.

I would like to use TripleDES but it isnt a requirement, just want something relatively strong for plain text communication (will either use JSON or just plain key-value pairs for complex stuff).

Thanks in advance

PS: http://pastie.org/643106 this is what I have been testing with.

A: 

Have you looked at mcrypt? Since it has many ciphers. Including MCRYPT_TRIPLEDES (libmcrypt > 2.4.x only)

Ólafur Waage
I have, but I cant get a consistent encription/decription in C# to PHP and back.Heres what I have so far : http://pastie.org/643106
SilentWarrior
+1  A: 

The most likely cause for you discrepancies is different text encodings. Since PHP is usually pretty bad with alternate text encodings, I would suggest pure ASCII.

Secondly, AES would be my preference for encryption, since there are solid, compatble implementations in PHP, JavaScript and .NET

John Gietzen
Can you post some examples on how to make it consistent, from what i read i should use base64.
SilentWarrior