I tried to encrypt data using this function in PHP and decrypt it with the other function in C#. But I don't get the same string.
//php function public function onCrypt($text) { $key=md5('DFDFDFDFDFDFDFDFDFDFDFDF',true); $crypttext = urldecode(trim(mcrypt_encrypt(MCRYPT_RIJNDAEL_128,$key, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_RAND)))); $text_crp =base64_encode($crypttext); return $text_crp; } //c# function
//public static void DecryptFile Parameters : strKey : the key choosed in decryption . PathPlainTextFile : path of the crypted file PathPlainTextFile : the original file decrypted.
public static void DecryptFile(string strKey, string pathPlainTextFile, string pathCypheredTextFile) { //crypt key with md5 function System.Security.Cryptography.MD5 alg = System.Security.Cryptography.MD5.Create(); System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); byte[] md5val = alg.ComputeHash(enc.GetBytes(strKey)); StreamReader fsPlainTextFile = File.OpenText(pathPlainTextFile); FileInfo t = new FileInfo(pathCypheredTextFile); StreamWriter Tex =t.CreateText(); string input = null; while ((input = fsPlainTextFile.ReadLine()) != null) { byte[] cipheredData = Convert.FromBase64String(input); RijndaelManaged rijndaeld = new RijndaelManaged(); // define the used mode rijndaeld.Mode = CipherMode.ECB; // create the cipher AES - Rijndael ICryptoTransform decryptor = rijndaeld.CreateDecryptor(md5val,null); // Write the ciphered data in MemoryStream MemoryStream ms= new MemoryStream(cipheredData); CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read); // Insert the ciphered data in a byte array byte[] plainTextData = new byte[cipheredData.Length]; int decryptedByteCount = cs.Read(plainTextData, 0, plainTextData.Length); ms.Close(); cs.Close(); // Insert the ciphered data in string encoded on Base64 Tex.WriteLine (Encoding.UTF8.GetString(plainTextData, 0, decryptedByteCount)); } Tex.Close(); }