Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.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/283.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 - Fatal编程技术网

加密PHP->;C#

加密PHP->;C#,c#,php,C#,Php,我想将php代码转换为c代码: PHP代码: $key = "xxxxxxxxxxxx"; $message = "MY MESSAGE"; $iv_length = mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB ); $iv = mcrypt_create_iv( $iv_length, MCRYPT_RAND ); $encrypted = mcrypt_encrypt( MCRYPT_RIJNDAEL_256, $key

我想将php代码转换为c代码:

PHP代码:

$key = "xxxxxxxxxxxx";
$message = "MY MESSAGE";

$iv_length = mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB );
$iv = mcrypt_create_iv( $iv_length, MCRYPT_RAND );
$encrypted = mcrypt_encrypt( MCRYPT_RIJNDAEL_256, $key, $message, MCRYPT_MODE_CFB, $iv );
$result = base64_encode( $iv . $encrypted );
C#代码:

但它不起作用。 php代码不接受来自C#的编码字符串

你能帮我吗


谢谢

Define“但它不起作用”。发生了什么。php不接受uncryptDefine的结果“但它不起作用”。发生了什么。php不接受uncrypt的结果
public static string Encrypt(string message, string key)
{
    var text = Encoding.Default.GetBytes(message);
    using (var aes = new RijndaelManaged())
    {
        aes.BlockSize = 256;
        aes.KeySize = 256;
        aes.Padding = PaddingMode.Zeros;
        aes.Mode = CipherMode.CFB;
        aes.GenerateIV();
        var encryptor = aes.CreateEncryptor(Encoding.Default.GetBytes(key), aes.IV);
        using (var ms = new MemoryStream())
        {
            using (var cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
            {
                cs.Write(text, 0, text.Length);
                cs.FlushFinalBlock();
            }
                var byteResult = new byte[aes.IV.Length + ms.ToArray().Length];
                Buffer.BlockCopy(aes.IV, 0, byteResult, 0, aes.IV.Length);
                Buffer.BlockCopy(ms.ToArray(), 0, byteResult, aes.IV.Length, ms.ToArray().Length);
                return Convert.ToBase64String(byteResult);
        }

    }
}