What is the function of MCRYPT in PHP and how is it commonly used?

MCRYPT is a PHP extension that provides encryption and decryption functions. It is commonly used to encrypt sensitive data such as passwords before storing them in a database. To use MCRYPT, you need to first enable the extension in your PHP configuration.

// Enable the MCRYPT extension in your PHP configuration

// Encrypt a string using MCRYPT
$plaintext = "Hello, World!";
$key = "secretkey";
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_CBC);

// Decrypt the encrypted string
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $ciphertext, MCRYPT_MODE_CBC);
echo $decrypted;