Can the mcrypt functions in the encode and decode methods be easily replaced with openssl_encrypt and openssl_decrypt in PHP?

Yes, the mcrypt functions in the encode and decode methods can be easily replaced with openssl_encrypt and openssl_decrypt in PHP. Simply replace the mcrypt functions with their openssl equivalents in the code snippet to ensure compatibility with newer PHP versions.

function encode($data, $key) {
    $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
    $encrypted = openssl_encrypt($data, 'aes-256-cbc', $key, 0, $iv);
    return base64_encode($iv . $encrypted);
}

function decode($data, $key) {
    $data = base64_decode($data);
    $iv = substr($data, 0, openssl_cipher_iv_length('aes-256-cbc'));
    $encrypted = substr($data, openssl_cipher_iv_length('aes-256-cbc'));
    return openssl_decrypt($encrypted, 'aes-256-cbc', $key, 0, $iv);
}