3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class Encryption { // The key const KEY = '36F3D40A7A41A827968BE75A87D6095036F3D40A7A41A827968BE75A87D60950'; /** * Encrypt a string * * @access public * @static * @param string $string * @return string */ public static function encrypt($string) { return mcrypt_encrypt(MCRYPT_RIJNDAEL_256, self::getMySQLKey(self::KEY), self::getPaddedString($string), MCRYPT_MODE_CBC, self::KEY); } /** * Decrypt a string * * @access public * @static * @param string $string * @return string */ public static function decrypt($string) { return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, self::getMySQLKey(self::KEY), $string, MCRYPT_MODE_CBC, self::KEY), "\x00..\x10"); } /** * Get MySQL key * * @access public * @static * @param string $key * @return string */ public static function getMySQLKey($key) { // The new key $new_key = str_repeat(chr(0), 32); // Iterate over the key and XOR for ($i = 0, $l = strlen($key); $i < $l; ++$i) { $new_key[$i % 32] = $new_key[$i % 32] ^ $key[$i]; } // Return the new key return $new_key; } /** * Get padded string * * @access public * @static * @param string $string * @return string */ public static function getPaddedString($string) { return str_pad($string, (16 * (floor(strlen($string) / 16) + 1)), chr(16 - (strlen($string) % 16))); } } echo base64_encode(Encryption::encrypt('michael@example.com'));
Output for 7.0.6 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Call to undefined function mcrypt_encrypt() in /in/nbniK:18 Stack trace: #0 /in/nbniK(74): Encryption::encrypt('michael@example...') #1 {main} thrown in /in/nbniK on line 18
Process exited with code 255.
Output for 5.6.8 - 5.6.20, 7.0.0 - 7.0.5
Warning: mcrypt_encrypt(): Received initialization vector of size 64, but size 32 is required for this encryption mode in /in/nbniK on line 18
Output for 5.5.35, 5.6.21 - 5.6.28
Fatal error: Call to undefined function mcrypt_encrypt() in /in/nbniK on line 18
Process exited with code 255.
Output for 5.5.24 - 5.5.34
Warning: mcrypt_encrypt(): The IV parameter must be as long as the blocksize in /in/nbniK on line 18 duoRB5kf+rlkoV2iVpOSozFog3GUp5nZbqGFgfsEYpg=

preferences:
171.67 ms | 401 KiB | 228 Q