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

80
August 23, 2021, at 5:30 PM

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 1

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!
READ ALSO
How to bind “non mouse action” event to a dymaically created object in JQuery?

How to bind “non mouse action” event to a dymaically created object in JQuery?

I am using multiselect plugin for my multiple select dropdownsHere is the code:

106
Can't ignore Content Description on new app

Can't ignore Content Description on new app

I have developed two other apps and was able to drop the Content Description when they runHowever, a new app I am working on will not drop it

96
Problem matching data in tables using regex

Problem matching data in tables using regex

Here, I want to update categoryName for image2 wherever characters in categoryID (image2) matches with categorID (image1)however, I want for categoryID "AA BB"(image2) should have category name updated as Archeology, Business

118
Using node-fetch module how can I use authenticated proxies?

Using node-fetch module how can I use authenticated proxies?

My goal is to send a request using node-fetch with authenticated proxies (Host, Port, Username and Password)I've been using https-proxy-agent but I get an error every time any other ways to use an authenticated proxy with node-fetch? Code:

42