3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php error_reporting(1); ini_set('display_errors', 1); class Encryption { private $key = "myKeyIs"; protected $iv_size; protected $iv; public function __construct(){ $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) { $input = $input; $output = $this->encrypt($input); return $output; } public function decryptData($input) { $input = $input; $output = $this->decrypt($input); return $output; } public 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; } public 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);
based on aBDWW
Output for 7.0.6 - 7.2.0
Fatal error: Uncaught Error: Call to undefined function mcrypt_get_iv_size() in /in/EVLkr:13 Stack trace: #0 /in/EVLkr(59): Encryption->__construct() #1 {main} thrown in /in/EVLkr on line 13
Process exited with code 255.
Output for 5.6.8 - 5.6.20, 7.0.0 - 7.0.5
Output for 5.3.20 - 5.3.29, 5.5.35, 5.6.21 - 5.6.28
Fatal error: Call to undefined function mcrypt_get_iv_size() in /in/EVLkr on line 13
Process exited with code 255.
Output for 5.4.10 - 5.5.34
hCaIoMokbIjLlnFnlrS3Iw== bk-T�m�����w/�