title: What is the mcrypt_get_block alternative and how to use it
body: <p>I have an old wordpress plugin built using symfony framework and which uses <code>mcrypt_get_block_size('tripledes', 'ecb')</code>. However, I have just upgraded php on my server to version 7.3 and now I am getting a <code>Fatal error: Call to undefined function HealthShieldForm\mcrypt_encrypt()</code>.</p>
  
  <p>I have read few articles where they suggest using <code>openssl_encrypt()</code>. Unfortunately I dont know where to begin in terms of replacing the functions with eachother and insure I am getting the same results.</p>
  
  <p>My current code is this:</p>
  
  <pre><code>private function encrypt($data)
      {
          //Pad for PKCS7
          $blockSize = mcrypt_get_block_size('tripledes', 'ecb');
          $len = strlen($data);
          $pad = $blockSize - ($len % $blockSize);
          $data .= str_repeat(chr($pad), $pad);
  
          //Encrypt data
          $encData = mcrypt_encrypt('tripledes', $this-&gt;key, $data, 'ecb');
  
          return base64_encode($encData);
      }
  
      private function decrypt($data)
      {
          $data = base64_decode($data);
  
          $data = mcrypt_decrypt('tripledes', $this-&gt;key, $data, 'ecb');
  
          $block = mcrypt_get_block_size('tripledes', 'ecb');
          $len = strlen($data);
          $pad = ord($data[$len - 1]);
  
          return substr($data, 0, strlen($data) - $pad);
      }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have adapted Peter's example to reflect on my code:</p>
  
  <pre><code>function encrypt($data)
      {
          $ciphertext = openssl_encrypt($data, 'des-ede3-ecb', $this-&gt;key, OPENSSL_RAW_DATA);
          return base64_encode($ciphertext);
      }
  
      function decrypt($data)
      {
          $ciphertext = base64_decode($data);
          $plaintext = openssl_decrypt($ciphertext, 'des-ede3-ecb', $this-&gt;key, OPENSSL_RAW_DATA);
          return $plaintext;
      }
  </code></pre>
  
  <p>However, now I am getting this error: <code>Warning: openssl_encrypt(): Unknown cipher algorithm</code></p>