3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php final class Encryption { // The key const KEY = 'EB648D0BFCA30CADC75634B10C5A3A341F8BDC268069CA2F2EB79D3BF8D58D00'; /** * 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'));
based on FpJar
Output for 7.0.6 - 7.2.0
Fatal error: Uncaught Error: Call to undefined function mcrypt_encrypt() in /in/vNm49:19 Stack trace: #0 /in/vNm49(75): Encryption::encrypt('michael@example...') #1 {main} thrown in /in/vNm49 on line 19
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/vNm49 on line 19
Output for 5.3.21 - 5.3.29, 5.5.35, 5.6.21 - 5.6.28
Fatal error: Call to undefined function mcrypt_encrypt() in /in/vNm49 on line 19
Process exited with code 255.
Output for 5.4.11 - 5.5.34
Warning: mcrypt_encrypt(): The IV parameter must be as long as the blocksize in /in/vNm49 on line 19 cTMgx0SjYqOa/p1nbmKn8MFoTCxcffZ+5CVweHVhgWo=