3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { protected $mcrypt_cipher = MCRYPT_RIJNDAEL_128; protected $mcrypt_mode = MCRYPT_MODE_CBC; public function decrypt($key, $iv, $encrypted) { return mcrypt_decrypt($this->mcrypt_cipher, $key, base64_decode($encrypted), $this->mcrypt_mode, $iv); } public function encrypt($key, $iv, $password) { $block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $padding = $block - (strlen($password) % $block); $password .= str_repeat(chr($padding), $padding); return mcrypt_encrypt($this->mcrypt_cipher, $key, $password, $this->mcrypt_mode, $iv); } } $foo = new Foo; $pass = 'p@ss'; $salt = 's@1t'; $key = PBKDF1($pass, $salt, 2, 32); $iv = "@1B2c3D4e5F6g7H8"; $encrypted = $foo->encrypt($key,$iv,'test@123'); $encrypted = base64_encode($encrypted); echo 'Encrypted: '.$encrypted.'</br>'; echo 'Decrypted: '.$foo->decrypt($key, $iv, $encrypted); function PBKDF1($pass, $salt, $count, $cb) { static $base; static $extra; static $extracount= 0; static $hashno; static $state = 0; if ($state == 0) { $hashno = 0; $state = 1; $key = $pass . $salt; $base = sha1($key, true); for($i = 2; $i < $count; $i++) { $base = sha1($base, true); } } $result = ""; if ($extracount > 0) { $rlen = strlen($extra) - $extracount; if ($rlen >= $cb) { $result = substr($extra, $extracount, $cb); if ($rlen > $cb) { $extracount += $cb; } else { $extra = null; $extracount = 0; } return $result; } $result = substr($extra, $rlen, $rlen); } $current = ""; $clen = 0; $remain = $cb - strlen($result); while ($remain > $clen) { if ($hashno == 0) { $current = sha1($base, true); } else if ($hashno < 1000) { $n = sprintf("%d", $hashno); $tmp = $n . $base; $current .= sha1($tmp, true); } $hashno++; $clen = strlen($current); } // $current now holds at least as many bytes as we need $result .= substr($current, 0, $remain); // Save any left over bytes for any future requests if ($clen > $remain) { $extra = $current; $extracount = $remain; } return $result; }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught Error: Undefined constant "MCRYPT_RIJNDAEL_128" in /in/Wh5Pp:19 Stack trace: #0 {main} thrown in /in/Wh5Pp on line 19
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught Error: Undefined constant "MCRYPT_RIJNDAEL_128" in /in/Wh5Pp:19 Stack trace: #0 {main} thrown in /in/Wh5Pp on line 19
Process exited with code 255.
Output for 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Warning: Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128' (this will throw an Error in a future version of PHP) in /in/Wh5Pp on line 19 Warning: Use of undefined constant MCRYPT_MODE_CBC - assumed 'MCRYPT_MODE_CBC' (this will throw an Error in a future version of PHP) in /in/Wh5Pp on line 19 Fatal error: Uncaught Error: Call to undefined function mcrypt_get_block_size() in /in/Wh5Pp:13 Stack trace: #0 /in/Wh5Pp(27): Foo->encrypt('\xFA\xBF\xD8-N\x1Db\x10\xFB\xEF\x9A\xF7\n\x0F\x84...', '@1B2c3D4e5F6g7H...', 'test@123') #1 {main} thrown in /in/Wh5Pp on line 13
Process exited with code 255.
Output for 7.0.6 - 7.0.20, 7.1.0 - 7.1.20
Notice: Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128' in /in/Wh5Pp on line 19 Notice: Use of undefined constant MCRYPT_MODE_CBC - assumed 'MCRYPT_MODE_CBC' in /in/Wh5Pp on line 19 Fatal error: Uncaught Error: Call to undefined function mcrypt_get_block_size() in /in/Wh5Pp:13 Stack trace: #0 /in/Wh5Pp(27): Foo->encrypt('\xFA\xBF\xD8-N\x1Db\x10\xFB\xEF\x9A\xF7\n\x0F\x84...', '@1B2c3D4e5F6g7H...', 'test@123') #1 {main} thrown in /in/Wh5Pp on line 13
Process exited with code 255.
Output for 5.5.24 - 5.5.34, 5.6.8 - 5.6.20, 7.0.0 - 7.0.5
Encrypted: miF7Ydzk1hfrCadxvii9GA==</br>Decrypted: test@123
Output for 5.5.35, 5.6.21
Notice: Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128' in /in/Wh5Pp on line 19 Notice: Use of undefined constant MCRYPT_MODE_CBC - assumed 'MCRYPT_MODE_CBC' in /in/Wh5Pp on line 19 Fatal error: Call to undefined function mcrypt_get_block_size() in /in/Wh5Pp on line 13
Process exited with code 255.

preferences:
162.06 ms | 401 KiB | 180 Q