3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Cipher { private $securekey, $iv; function __construct($textkey) { $this->securekey = hash('sha256',$textkey,TRUE); $this->iv = mcrypt_create_iv(32); } function encrypt($input) { return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->securekey, $input, MCRYPT_MODE_ECB, $this->iv)); } function decrypt($input) { return rtrim(trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->securekey, base64_decode($input), MCRYPT_MODE_ECB, $this->iv)),"\0"); } } $cipher = new Cipher('secret passphrase'); $encryptedtext = $cipher->encrypt("hide me"); echo "->encrypt = $encryptedtext<br />"; $decryptedtext = $cipher->decrypt($encryptedtext); echo "->decrypt = $decryptedtext<br />"; var_dump($decryptedtext);
Output for 7.0.6 - 7.2.6
Fatal error: Uncaught Error: Call to undefined function mcrypt_create_iv() in /in/i6vFP:7 Stack trace: #0 /in/i6vFP(17): Cipher->__construct('secret passphra...') #1 {main} thrown in /in/i6vFP on line 7
Process exited with code 255.
Output for 5.4.0 - 5.5.34, 5.6.0 - 5.6.20, 7.0.0 - 7.0.5
->encrypt = qEGST6a1EeILR+62DComC+y3rlRssLNTI1gx5Fgo1Qw=<br />->decrypt = hide me<br />string(7) "hide me"
Output for 5.1.2 - 5.3.29, 5.5.35 - 5.5.38, 5.6.21 - 5.6.25
Fatal error: Call to undefined function mcrypt_create_iv() in /in/i6vFP on line 7
Process exited with code 255.
Output for 5.0.0 - 5.1.1
Fatal error: Call to undefined function hash() in /in/i6vFP on line 6
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/i6vFP on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/i6vFP on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/i6vFP on line 4
Process exited with code 255.