The issue is why does a 32 character string work in C# .NET but not in php mcrypt, and how to make them compatible? (I have a method of doing it with AES, 3DES remains open.
I'm trying to create a cryptography api which uses Microsofts Crypto Api's in .NET and PHP's mcrypt to encrypt and decrypt data.
C# should be able to encrypt and decrypt, the PhP only needs to decrypt. The problem is I would like the user to be able to define their own key. To do this, I have md5 hashed the password they enter. This works perfectly on the C # side, but in PHP I get
Warning: mcrypt_decrypt() [function.mcrypt-decrypt]: Size of key is too large for this algorithm in C:\xampp\htdocs\failcrypt\crypt.php on line 40
(An empty "" string should work, as well as fairly large keys.
All the links I can find have preset keys, but mine must work for arbitrary key sizes on both sides.
echo $key."</br>";
echo md5($key)."</br>";
$newKey = md5($key)."</br>";
echo strlen($newKey)."</br>";
$decrypted = mcrypt_decrypt(MCRYPT_3DES, md5($key), base64_decode($msg), MCRYPT_MODE_ECB);
echo $decrypted;
outputs
red (the key)
bda9643ac6601722a28f238714274da4 (the hash)
<br /> characters...