7.2 removed mcrypt and added libsodium to core in the same release, which is a clearer statement of intent than any deprecation notice.
$key = sodium_crypto_secretbox_keygen();
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$cipher = sodium_crypto_secretbox($plaintext, $nonce, $key);
$plain = sodium_crypto_secretbox_open($cipher, $nonce, $key);
if ($plain === false) {
throw new RuntimeException('tampered or wrong key');
}
sodium_memzero($key);
The API is deliberately small and gives you no choices to get wrong — no mode, no padding, no separate MAC step, and authentication is not optional. The nonce must never repeat for a given key, which is why it is generated rather than counted. Anything still calling mcrypt_encrypt needs a migration plan rather than a polyfill, because the extension is not coming back.