Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.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
c#和php中的三重加密不同_C#_Php_Encryption_Interop_Cryptography - Fatal编程技术网

c#和php中的三重加密不同

c#和php中的三重加密不同,c#,php,encryption,interop,cryptography,C#,Php,Encryption,Interop,Cryptography,PHP代码 define('SECRET', 'Your key here'); $data = 'test'; $enc = mcrypt_cbc(MCRYPT_TRIPLEDES, SECRET, $data, MCRYPT_ENCRYPT, '12345678'); $url .= urlencode($password); C#代码 我的问题是:PHP中的$url和c#中的szEnc的值不一样 问题:我的c#代码出了什么问题?很多事情都可能出错-但我在处理字符串和字节[]时看到了很

PHP代码

define('SECRET', 'Your key here');
$data = 'test';

$enc = mcrypt_cbc(MCRYPT_TRIPLEDES, SECRET, $data, MCRYPT_ENCRYPT, '12345678');

$url .= urlencode($password);
C#代码

我的问题是:PHP中的$url和c#中的szEnc的值不一样


问题:我的c#代码出了什么问题?

很多事情都可能出错-但我在处理
字符串和
字节[]
时看到了很多编码(即非加密)问题

永远不要假设它们会转换成任何东西,包括ASCII

Encoding.ASCII.GetString(enc)
如果您有不可打印的字符,NUL。。。然后这将不是返回字符串的一部分,并且不会进行url编码。这对于PHP是正确的,但并不意味着它在所有情况下都遵循相同的规则

我也不能告诉您代码是什么样的:

ec.GetBytes("Your key here");
行吗?!?如果您使用的是Unicode编码器,那么它不会提供与ASCII编码器相同的结果


除了编码之外,还要检查您使用的
PaddingMode
是否与PHP使用的模式匹配。

/
在C代码中,在PHP代码中是
8
。在这里提问时,请复制并粘贴您的代码,而不是重新键入。对不起,我的键入错误。但是我的问题没有解决,现在你完全忽略了
8
。请不要重新键入。复制和。粘贴:)可能重复的只是使用查找和替换来编辑您的数据谢谢您的回答。我使用1252编码代替ASCII,我的问题得到了解决。谢谢你的回答。
ec.GetBytes("Your key here");