title: TRIPLE DES encryption/decryption using php
body: <p>I have this TRIPLE DES ENCRYPTION CODE IN PHP</p>
  
  <pre><code>    $encryption_key = "CE51E06875F7D964";
      $data='tokenNo=test&amp;securityCode=111' ;
      echo $desEncryptedData = encryptText_3des($data, $encryption_key);//outputs 3des encrypted data
  
  function encryptText_3des($plainText, $key) {
      $key = hash("md5", $key, TRUE); 
      for ($x=0;$x&lt;8;$x++) {
          $key = $key.substr($key, $x, 1);
      }
      $padded = pkcs5_pad($plainText,
          mcrypt_get_block_size(MCRYPT_3DES, MCRYPT_MODE_CBC));
      $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_3DES, $key, $padded, MCRYPT_MODE_CBC));
      return $encrypted;
  }
   function pkcs5_pad ($text, $blocksize)   
  {
      $pad = $blocksize - (strlen($text) % $blocksize);
      return $text . str_repeat(chr($pad), $pad);
  }
  </code></pre>
  
  <p>Im able to encrypt the data as <code>xcFEvIdLXc2fjhG1i4iPOQu5L6ahxwZVucDOPqeMM2E=</code></p>
  
  <p>Now I have the key,will I able to decrypt this data to plain text format?</p>
  
  <p>I tried it this way</p>
  
  <pre><code>            $encryption_key = "CE51E06875F7D964";
          $data='xcFEvIdLXc2fjhG1i4iPOQu5L6ahxwZVucDOPqeMM2E=' ; //encrypted data
          echo $desEncryptedData = encryptText_3des($data, $encryption_key);//outputs 3des encrypted data
  
      function encryptText_3des($plainText, $key) {
          $key = hash("md5", $key, TRUE); 
          for ($x=0;$x&lt;8;$x++) {
              $key = $key.substr($key, $x, 1);
          }
          $padded = pkcs5_unpad($plainText,
              mcrypt_get_block_size(MCRYPT_3DES, MCRYPT_MODE_CBC));
          $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_3DES, $key, $padded, MCRYPT_MODE_CBC));
          return $encrypted;
      }
  
      function pkcs5_unpad($text)   
  
      {
          $pad = ord($text{strlen($text)-1});
          if ($pad &gt; strlen($text)) return false;
          if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false;
          return substr($text, 0, -1 * $pad);
      }
  </code></pre>
  
  <p>But I couldnt do it.IS what I am doing is wrong?Please suggest me a way to decrypt this?Is the encryption key itself is used to decrypt the data in triple DES?Please help</p>