3v4l.org

run code in 300+ PHP versions simultaneously
<? /* * 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); ?>
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.32, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<? /* * 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); ?>
Output for 8.0.13
Warning: Undefined variable $HashAlgorithm in /in/i2tt9 on line 15 Fatal error: Uncaught ValueError: hash(): Argument #1 ($algo) must be a valid hashing algorithm in /in/i2tt9:15 Stack trace: #0 /in/i2tt9(15): hash('', 'passpharse', true) #1 /in/i2tt9(26): Cipher->__construct('passpharse') #2 {main} thrown in /in/i2tt9 on line 15
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.13, 7.3.0 - 7.3.1, 7.4.33
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 7.3.32 - 7.3.33
Warning: hash(): Unknown hashing algorithm: in /in/i2tt9 on line 15 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.5.0 - 5.5.38, 5.6.0 - 5.6.38
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.

preferences:
216.23 ms | 402 KiB | 294 Q