title: Porting C# TripleDESCryptoServiceProvider encryption to PHP
body: <p>There's a project written in C# which uses the following code to encrypt/decrypt data to/from database:</p>
  
  <pre><code>public string EncryptString(string Text)
  {
      byte[] IV = new byte[8] { 1, 2, 3, 4, 5, 6, 7, 8 };
      string Key = "abcdef";
      byte[] buffer = Encoding.UTF8.GetBytes(Text);
      TripleDESCryptoServiceProvider triple = new TripleDESCryptoServiceProvider();
      MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
      triple.IV = IV;
      triple.Key = md5.ComputeHash(ASCIIEncoding.UTF8.GetBytes(Key));
      byte[] encodeText = triple.CreateEncryptor().TransformFinalBlock(buffer, 0, buffer.Length);
      string user = Convert.ToBase64String(encodeText);
      return user;
  }
  
  public static string DecryptString(string EncryptText)
  {
      byte[] IV = new byte[8] { 1, 2, 3, 4, 5, 6, 7, 8 };
      string Key = "abcdef";
      byte[] decodeText = null;
      byte[] buffer = Convert.FromBase64String(EncryptText);
      TripleDESCryptoServiceProvider triple = new TripleDESCryptoServiceProvider();
      MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
      triple.IV = IV;
      triple.Key = md5.ComputeHash(ASCIIEncoding.UTF8.GetBytes(Key));
      decodeText = triple.CreateDecryptor().TransformFinalBlock(buffer, 0, buffer.Length);
      return Encoding.UTF8.GetString(decodeText);
  }
  </code></pre>
  
  <p>Now I'm supposed to do the same in PHP. So far I came as close as the following code:</p>
  
  <pre><code>define('CIPHER', 'tripledes');
  define('MODE', 'cbc');
  
  function Encrypt($data)
  { 
      $iv = chr(1) . chr(2) . chr(3) . chr(4) . chr(5) . chr(6) . chr(7) . chr(8);
      $key = 'abcdef';
      $tripleKey = substr(md5($key), 0, mcrypt_get_key_size(CIPHER, MODE));
      $encodedText = mcrypt_encrypt(CIPHER, $tripleKey, $data, MODE, $iv);
      return base64_encode($encodedText);
  }
  
  function Decrypt($data)
  {
      $iv = chr(1) . chr(2) . chr(3) . chr(4) . chr(5) . chr(6) . chr(7) . chr(8);
      $key = 'abcdef';
      $tripleKey = substr(md5($key), 0, mcrypt_get_key_size(CIPHER, MODE));
      $decodedText = mcrypt_decrypt(CIPHER, $tripleKey, base64_decode($data), MODE, $iv);
      return $decodedText;
  }
  </code></pre>
  
  <p>But I can not decrypt a string encrypted by the C#'s code! I'm no encryption expert, could someone please tell me which encryption algorithm and which mode should I use?</p>