Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP加密字符串,用C#解密?_C#_Php_.net_Winforms_Encryption Symmetric - Fatal编程技术网

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

用PHP加密字符串,用C#解密?,c#,php,.net,winforms,encryption-symmetric,C#,Php,.net,Winforms,Encryption Symmetric,在action.php页面中,我有一个字符串要存储在mysql中,但我想在将其插入数据库之前对其进行加密 $data = "Hello World"; $data = Encrypt_This_String($data,"ABCD"); // abcd is a key // now I insert this string into MySQL database 另一方面,我需要从C#.NET应用程序中获取此字符串,因此我需要执行以下操作: string myStr = getMyS

在action.php页面中,我有一个字符串要存储在mysql中,但我想在将其插入数据库之前对其进行加密

 $data = "Hello World";
 $data = Encrypt_This_String($data,"ABCD"); // abcd is a key
 // now I insert this string into MySQL database
另一方面,我需要从C#.NET应用程序中获取此字符串,因此我需要执行以下操作:

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

 myStr = Decrypt_String(myStr,"ABCD");
我需要myStr具有“Hello World”的值

有人能给我一个基于密钥的加密算法,可以在PHP和C#中使用吗?

您可以使用Rijndael(AES 128):

用于加密来自PHP的数据,例如CBC模式下的AES作为密码;文档页面上有示例代码


然后使用或从C#解密,MSDN上的两个页面都有示例代码。

加密必须有多安全?AES-CBC和HMAC-SHA-256可以使用它们附带的LIB实现。您可能还需要MAC。没有MAC的CBC通常可以使用填充预言符来破坏。C#示例使用ECB和ASCII编码作为密钥。php代码缺少MAC,也没有IV。这些都不是很好的例子。