3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<? /* * DEFINE CONSTANTS */ $HashPassPhrase = "passpharse"; $HashSalt = "saltvalue"; $HashAlgorithm = "SHA1"; $HashIterations = "2"; $InitVector = "1a2b3c4d5e6f7g8h"; // Must be 16 bytes $keySize = "256"; class Cipher { private $securekey, $iv; function __construct($textkey) { $this->securekey = hash($HashAlgorithm,$textkey,TRUE); $this->iv = $InitVector; } function encrypt($input) { return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->securekey, $input, MCRYPT_MODE_CBC, $this->iv)); } function decrypt($input) { return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->securekey, base64_decode($input), MCRYPT_MODE_CBC, $this->iv)); } } $cipher = new Cipher($HashPassPhrase); $encryptedtext = $cipher->encrypt("Text To Encrypt"); echo "->encrypt = $encryptedtext<br />"; $decryptedtext = $cipher->decrypt($encryptedtext); echo "->decrypt = $decryptedtext<br />"; var_dump($cipher); ?>
based on f4S4F
Output for 7.0.6 - 7.2.0
Notice: Undefined variable: HashAlgorithm in /in/i2tt9 on line 15 Warning: hash(): Unknown hashing algorithm: in /in/i2tt9 on line 15 Notice: Undefined variable: InitVector in /in/i2tt9 on line 16 Fatal error: Uncaught Error: Call to undefined function mcrypt_encrypt() in /in/i2tt9:19 Stack trace: #0 /in/i2tt9(28): Cipher->encrypt('Text To Encrypt') #1 {main} thrown in /in/i2tt9 on line 19
Process exited with code 255.
Output for 5.6.8 - 5.6.20, 7.0.0 - 7.0.5
Notice: Undefined variable: HashAlgorithm in /in/i2tt9 on line 15 Warning: hash(): Unknown hashing algorithm: in /in/i2tt9 on line 15 Notice: Undefined variable: InitVector in /in/i2tt9 on line 16 Warning: mcrypt_encrypt(): Key of size 0 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in /in/i2tt9 on line 19 ->encrypt = <br /> Warning: mcrypt_decrypt(): Key of size 0 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in /in/i2tt9 on line 22 ->decrypt = <br />object(Cipher)#1 (2) { ["securekey":"Cipher":private]=> bool(false) ["iv":"Cipher":private]=> NULL }
Output for 5.5.35, 5.6.21 - 5.6.28
Notice: Undefined variable: HashAlgorithm in /in/i2tt9 on line 15 Warning: hash(): Unknown hashing algorithm: in /in/i2tt9 on line 15 Notice: Undefined variable: InitVector in /in/i2tt9 on line 16 Fatal error: Call to undefined function mcrypt_encrypt() in /in/i2tt9 on line 19
Process exited with code 255.
Output for 5.4.10 - 5.5.34
Notice: Undefined variable: HashAlgorithm in /in/i2tt9 on line 15 Warning: hash(): Unknown hashing algorithm: in /in/i2tt9 on line 15 Notice: Undefined variable: InitVector in /in/i2tt9 on line 16 Warning: mcrypt_encrypt(): The IV parameter must be as long as the blocksize in /in/i2tt9 on line 19 ->encrypt = pgL++MheHwGS89doMrSf+nLBP6ho6AqomOORY5Z4CmI=<br /> Warning: mcrypt_decrypt(): The IV parameter must be as long as the blocksize in /in/i2tt9 on line 22 ->decrypt = Text To Encrypt<br />object(Cipher)#1 (2) { ["securekey":"Cipher":private]=> bool(false) ["iv":"Cipher":private]=> NULL }
Output for 5.3.20 - 5.3.29
<? /* * DEFINE CONSTANTS */ $HashPassPhrase = "passpharse"; $HashSalt = "saltvalue"; $HashAlgorithm = "SHA1"; $HashIterations = "2"; $InitVector = "1a2b3c4d5e6f7g8h"; // Must be 16 bytes $keySize = "256"; class Cipher { private $securekey, $iv; function __construct($textkey) { $this->securekey = hash($HashAlgorithm,$textkey,TRUE); $this->iv = $InitVector; } function encrypt($input) { return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->securekey, $input, MCRYPT_MODE_CBC, $this->iv)); } function decrypt($input) { return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->securekey, base64_decode($input), MCRYPT_MODE_CBC, $this->iv)); } } $cipher = new Cipher($HashPassPhrase); $encryptedtext = $cipher->encrypt("Text To Encrypt"); echo "->encrypt = $encryptedtext<br />"; $decryptedtext = $cipher->decrypt($encryptedtext); echo "->decrypt = $decryptedtext<br />"; var_dump($cipher); ?>