tags:

views:

55

answers:

3

Hello,

I am looking for 2 lines of code, one which will encrypt (using a shared key) a string in ASP and the other will decode the same string in PHP.

Can someone please suggest.

A: 

You will need more than one line of code per language for that.

For ASP you can use a component called CAPICOM that is included with Windows, for PHP the encryption functions is among all other functions. The gotcha I remember from doing this is that the input to capicom is sent as unicode per default. Your best bet is probably to convert the unicode to ascii or something when you get it back from the decryption function in PHP.

svinto
+2  A: 

Using standard APIs, I doubt it will be possible to do in two lines. So if "two lines" is a strict requirement, I recommend starting an external process. Make sure you have openssl installed on both systems, and use the 'openssl enc' command.

To encrypt, do

openssl enc -aes-256-cbc -salt -k PASSWORD -in /tmp/infile -out /tmp/encrypted

To decrypt, do

openssl enc -d -aes-256-cbc -salt -k PASSWORD -in /tmp/encrypted -out /tmp/decrypted
Martin v. Löwis
2 lines is not a requirement, but I was hoping to use some code and not external commands.
Alec Smart
I mentioned 2 lines, because I thought it would be very similar to MD5 hashing or something. like $newstring = md5("test");
Alec Smart
A: 

There's always str_rot13()! ;-)

ceejayoz