3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(1); ini_set('display_errors', 1); class Encryption { private $key; protected $iv_size; protected $iv; public function __construct(){ $this->key = pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3"); $this->iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $this->iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); } public function encryptData($input) { $output = $this->encrypt($input); return $output; } public function decryptData($input) { $output = $this->decrypt($input); return $output; } protected function decrypt($string) { $string = base64_decode($string); # retrieves the IV, iv_size should be created using mcrypt_get_iv_size() $iv_dec = substr($string, 0, $this->iv_size); # retrieves the cipher text (everything except the $iv_size in the front) $string = substr($string, $this->iv_size); # may remove 00h valued characters from end of plain text $output = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->key, $string, MCRYPT_MODE_CBC, $iv_dec); return $output; } protected function encrypt($string) { $output = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->key, $string, MCRYPT_MODE_CBC, $this->iv); # prepend the IV for it to be available for decryption $output = $this->iv . $output; # encode the resulting cipher text so it can be represented by a string $output = base64_encode($output); return $output; } } $test = new Encryption(); $encrypted = $test->encryptData("Vicky"); echo $encrypted."\n"; echo $test->decryptData($encrypted);
Output for 7.0.0 - 7.0.33, 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.4, 8.3.6
Fatal error: Uncaught Error: Call to undefined function mcrypt_get_iv_size() in /in/8gbkM:14 Stack trace: #0 /in/8gbkM(58): Encryption->__construct() #1 {main} thrown in /in/8gbkM on line 14
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: Call to undefined function mcrypt_get_iv_size() in /in/8gbkM:14 Stack trace: #0 /in/8gbkM(58): Encryption->__construct() #1 {main} thrown in /in/8gbkM on line 14
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40
Fatal error: Call to undefined function mcrypt_get_iv_size() in /in/8gbkM on line 14
Process exited with code 255.

preferences:
250.44 ms | 402 KiB | 330 Q