'Use phpseclib to decrypt mcrypt rijndael-256 encrypted data

We have some legacy code that looks like this:

$crypt = mcrypt_module_open('rijndael-256', '', 'ofb', '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($crypt), MCRYPT_DEV_URANDOM);
$ks = mcrypt_enc_get_key_size($crypt);
mcrypt_generic_init($crypt, $key, $iv);
$encrypted = base64_encode(mcrypt_generic($crypt, $plain));

I am aware that this legacy code needs to be removed (mcrypt is deprecated) and need to find out if I can decrypt the data with something other than mcrypt... or if we need to find a way to migrate the data to another encryption scheme entirely ahead of removal of mcrypt.

Is there equivalent PHPSecLib (or other?) code that can decrypt what mcrypt has encrypted here?

I've attempted this, but am not getting back valid results:

$iv_size = 32;
$cipher = new phpseclib3\Crypt\Rijndael('ofb');
$cipher->setBlockLength(256);
$cipher->setKey($key);
$cipher->setIV($iv);
echo $cipher->decrypt(base64_decode($encrypted));


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source