我有下面的C#代碼,但是我很難爲PHP mcrypt_decrypt()添加參數。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(字符串$密碼,字符串$鍵,字符串$數據, 串$模式[,字符串$ IV])
我的數據是: - 「iHcKDE0aeDZU3q31ULZcvQ ==」
Key-:「&%#@?,:*」
我想用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;
?>
您是否收到任何錯誤?你能發佈你在PHP中試過的東西,而不是C#代碼嗎? – bnlucas
echo mcrypt_decrypt(MCRYPT_3DES,$ key,$ ciphertext_dec,MCRYPT_MODE_CFB) –
我得到的輸出是¼p_‡