3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * MCrypt Library to enable encryption and decryption using MCrypt. * NOTE: this is an adjusted version of the below source. * SOURCE: https://raw.githubusercontent.com/serpro/Android-PHP-Encrypt-Decrypt/master/PHP/MCrypt.php */ class Mcrypt { /** * IV parameter */ private $iv = 'hoewhowhahwoahoe'; function __construct() { // empty } /** * @param string $str * @param bool $isBinary whether to encrypt as binary or not. Default is: false * @return string Encrypted data */ public function encrypt($str, $key, $isBinary = FALSE) { // variables $str = $isBinary ? $str : utf8_decode($str); $td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $this->iv); // guard: check if the str is valid if (empty($str)) { return $str; } mcrypt_generic_init($td, $key, $this->iv); $encrypted = mcrypt_generic($td, $str); mcrypt_generic_deinit($td); mcrypt_module_close($td); return $isBinary ? $encrypted : base64_encode(bin2hex($encrypted)); } /** * @param string $code * @param bool $isBinary whether to decrypt as binary or not. Default is: false * @return string Decrypted data */ public function decrypt($code, $key, $isBinary = FALSE) { // variables $code = $isBinary ? $code : $this->hex2bin(base64_decode($code)); $td = mcrypt_module_open('rijndael-128', ' ', 'cbc', $this->iv); // guard: check if the code is valid if (empty($code)) { return $code; } mcrypt_generic_init($td, $key, $this->iv); $decrypted = mdecrypt_generic($td, $code); mcrypt_generic_deinit($td); mcrypt_module_close($td); return $isBinary ? trim($decrypted) : utf8_encode(trim($decrypted)); } protected function hex2bin($hexdata) { $bindata = ''; for ($i = 0; $i < strlen($hexdata); $i += 2) { $bindata .= chr(hexdec(substr($hexdata, $i, 2))); } return $bindata; } } $mcrypt = new Mcrypt(); $key = "8f1ec9b37ccd2e88aa4279999818d28d"; $string = "OGZkM2M2NGI4MWRlMzg1MzlmZDRiN2ZjODA1NTM1MDA="; echo($mcrypt->decrypt($string, $key));
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
Fatal error: Uncaught Error: Call to undefined function mcrypt_module_open() in /in/QFBPr:57 Stack trace: #0 /in/QFBPr(89): Mcrypt->decrypt('\x8F\xD3\xC6K\x81\xDE8S\x9F\xD4\xB7\xFC\x80U5...', '8f1ec9b37ccd2e8...') #1 {main} thrown in /in/QFBPr on line 57
Process exited with code 255.
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 5.4.12, 5.5.28, 5.6.0 - 5.6.40
Fatal error: Call to undefined function mcrypt_module_open() in /in/QFBPr on line 57
Process exited with code 255.

preferences:
160.02 ms | 409 KiB | 5 Q