3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $string = "secret"; function getKey($seed='no seed??') { return hash('sha256', $seed, 1); } function encrypt($key, $string) { $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $iv = mcrypt_create_iv($size, MCRYPT_RAND); $encrypted_string = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_CBC, $iv); return base64_encode($iv . $encrypted_string); } function decrypt($key, $encoded_string) { $binary = base64_decode($encoded_string); $size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $iv = substr($binary, 0, $size); $encrypted_string = substr($binary, $size); return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $encrypted_string, MCRYPT_MODE_CBC, $iv); } $key = getKey('Some Secret String'); $encrypted = encrypt($key, 'This is a string that will be encrypted'); echo decrypt($key, $encrypted);
Output for 7.0.6 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function mcrypt_get_iv_size() in /in/diXEM:9 Stack trace: #0 /in/diXEM(26): encrypt('\x18\xAA\x853\xF6\xBD\xC1\xE3"\xEB\x078\xE5G\xC1...', 'This is a strin...') #1 {main} thrown in /in/diXEM on line 9
Process exited with code 255.
Output for 5.4.36 - 5.5.34, 5.6.7 - 5.6.20, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.0.5
This is a string that will be encrypted
Output for 5.1.2 - 5.4.35, 5.5.35, 5.6.21 - 5.6.28
Fatal error: Call to undefined function mcrypt_get_iv_size() in /in/diXEM on line 9
Process exited with code 255.
Output for 5.0.0 - 5.1.1
Fatal error: Call to undefined function hash() in /in/diXEM on line 5
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: hash() in /in/diXEM on line 5
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: hash() in /in/diXEM on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: hash() in /in/diXEM on line 5