I need to pass a 3DES encrypted string to a php web page from c# and i'm having no luck.
In short the PHP code I am trying to convert is :
$message = $request->get('searchHash');
$searchHash = base64_decode(rawurldecode($message));
$key = $this->container->getParameter("api_encryption_key");
$decrypted = mcrypt_decrypt(MCRYPT_3DES, $key, $searchHash, MCRYPT_MODE_ECB);
//$data = unserialize($decrypted);
$searchString = str_replace("\x0", '', $decrypted);
which I have re-wriiten as:
using (TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider())
{
byte[] iv0 = { 0, 0, 0, 0, 0, 0, 0, 0 };
byte[] toEncryptArray = Encoding.ASCII.GetBytes(toEncrypt);
tdes.IV = iv0;
tdes.Key = Encoding.ASCII.GetBytes(key);
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.Zeros;
ICryptoTransform cTransform = tdes.CreateEncryptor();
byte[] resultArray =
cTransform.TransformFinalBlock(toEncryptArray, 0,
toEncryptArray.Length);
tdes.Clear();
return resultArray.ToString();
}
however the results from c# are not consistent with those of php.
Can anyone shed any light as to why?
Thanks.