What are the potential pitfalls of using mcrypt() for encryption in PHP?

Using mcrypt() for encryption in PHP is not recommended as it is considered outdated and insecure. It has not been maintained since 2007 and has known security vulnerabilities. It is recommended to use the OpenSSL extension in PHP for encryption instead.

// Encrypt using OpenSSL extension
$plaintext = "Hello World";
$key = openssl_random_pseudo_bytes(32); // 256-bit key
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));

$ciphertext = openssl_encrypt($plaintext, 'aes-256-cbc', $key, 0, $iv);

echo "Encrypted text: " . $ciphertext;