我有以下 C# 代码,但我很难为 PHP mcrypt_decrypt() 添加参数。
private string Decrypt(string strText, string sDecrKey)
{
string message;
byte[] rgbKey = new byte[0];
byte[] rgbIV = new byte[] { 0x12, 0x34, 0x56, 120, 0x90, 0xab, 0xcd, 0xef };
byte[] buffer = new byte[strText.Length + 1];
try
{
rgbKey = Encoding.UTF8.GetBytes(Strings.Left(sDecrKey, 8));
DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
buffer = Convert.FromBase64String(strText);
MemoryStream stream2 = new MemoryStream();
CryptoStream stream = new CryptoStream(stream2, provider.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
stream.Write(buffer, 0, buffer.Length);
stream.FlushFinalBlock();
message = Encoding.UTF8.GetString(stream2.ToArray());
}
catch (Exception exception1)
{
ProjectData.SetProjectError(exception1);
Exception exception = exception1;
message = exception.Message;
ProjectData.ClearProjectError();
return message;
ProjectData.ClearProjectError();
}
return message;
}
字符串 mcrypt_decrypt ( 字符串 $cipher , 字符串 $key , 字符串 $data , 字符串 $mode [, 字符串 $iv ] )
我的数据是-:"iHcKDE0aeDZU3q31ULZcvQ=="
钥匙-: ”&%#@?,:*”
我想使用 PHP mcrypt_decrypt () 函数解密这些数据。我对 C# 的了解很少,但 PHP 很好。请帮帮我
<?php
$key = pack("nvc*",0x12, 0x34, 0x56, 120, 0x90, 0xab, 0xcd, 0xef);
$iv_size = mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_CFB)
$ciphertext_dec = base64_decode("iHcKDE0aeDZU3q31ULZcvQ==");
$iv_dec = substr($ciphertext_dec, 0, $iv_size);
$retval = mcrypt_decrypt(MCRYPT_3DES, $key, $ciphertext_dec, MCRYPT_MODE_CFB, $iv_dec);
echo $retval;
?>