用PHP加密字符串,用C#解密它?

In the action.php page, I have a string that I want to store in mysql but I want to encrypt it before inserting it to the db

 $data = "Hello World";
 $data = Encrypt_This_String($data,"ABCD"); // abcd is a key
 // now I insert this string into MySQL database

In the other side, I need to get back this string from my C#.NET application, so I need to do something like this :

 string myStr = getMyString(); // where getMyString() is a function that get the encrypted string from db

 myStr = Decrypt_String(myStr,"ABCD");

I need that myStr hold the value "Hello World"

Could someone please give me an encryption algorithm that is based on a key and can be used in both PHP and C# ?

You can use Rijndael (AES 128) :

PHP- AES128 Example

C# AES128 Example

Use mcrypt_encrypt to encrypt the data from PHP, with e.g. AES in CBC mode as the cipher; there is example code on the documentation page.

Then decrypt from C# using AesManaged or AesCryptoServiceProvider, both pages on MSDN have example code.