I have inherited some C # code and I need to port it to PHP. Here he is:
string key = "some key"; string strEncrypted = "some encrypted string"; byte[] hashedKey = new MD5CryptoServiceProvider().ComputeHash(UTF8Encoding.UTF8.GetBytes(key)); byte[] strToDecrypt = Convert.FromBase64String(strEncrypted); TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider(); tripleDES.Key = hashedKey; tripleDES.Mode = CipherMode.ECB; string strDecrypted = UTF8Encoding.UTF8.GetString(tripleDES.CreateDecryptor().TransformFinalBlock(strToDecrypt, 0, strToDecrypt.Length));
My PHP code looks like this:
$key = 'some key'; $str_encrypted = 'some encrypted string'; $hashed_key = md5($key, TRUE); $str_to_decrypt = base64_decode($str_encrypted);
But the two decrypted values do not match, and I cannot understand why. I read a lot of similar questions here and elsewhere, but none of them seem to explain what I have.
I would really appreciate any help in figuring out why the PHP decrypted string does not match the C # decrypted string.
c # php cryptography mcrypt
matthewwithanm
source share