简体   繁体   中英

Encode in ASP and decode in PHP

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.

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

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.

There's always str_rot13() ! ;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM