Looking for alternatives to mcrypt for PHP server using 'Twofish' encryption

At my workplace, our server is still running on an older PHP 5.6 but our host will soon stop supporting this version and we'll be upgrading to 7.x. Some of the data going through it gets encrypted/decrypted using the 'Twofish' algorithm into/out of our database.

The problem? My predecessor who wrote the script that handles the encryption was using the old 'dl()' command and relying the the 'mcrypt' library, which from my understanding via google searches are both no longer supported in newer PHP versions.

Since we're now too far in with lots of SQL tables already containing encrypted data, I'm looking for alternative ways to apply the 'Twofish' algorithm. What are some alternative options I can make use of going forward? Any libraries/sources I can rely on?

Answer

Solution:

A quick lookup for Twofish at Packagist will return the phpseclib package which requires PHP >= 5.6.1 and it has the phpseclib3/Crypt/Twofish class which you can use to encrypt/decrypt data like this:

use phpseclib3\Crypt\Twofish;

$tf = new Twofish('cbc');
$tf->setIV(str_repeat("\0", $tf->getBlockLength() >> 3));

// key size = 128
$key = pack('H*', '00000000000000000000000000000000');
$tf->setKey($key);

$ciphertext = $tf->encrypt('Encrypted text!');
echo $tf->decrypt($ciphertext); // Encrypted text!

Source