3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $this->partner_key = 1; $string = 'test_string'; # --- ENCRYPTION --- # the key should be random binary, use scrypt, bcrypt or PBKDF2 to # convert a string into a key # key is specified using hexadecimal $key = pack('H*', bin2hex($this->partner_key)); # show key size use either 16, 24 or 32 byte keys for AES-128, 192 # and 256 respectively $key_size = strlen($key); # create a random IV to use with CBC encoding $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); # creates a cipher text compatible with AES (Rijndael block size = 128) # to keep the text confidential # only suitable for encoded input that never ends with value 00h # (because of default zero padding) $ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_MODE_CBC, $iv); # prepend the IV for it to be available for decryption $ciphertext = $iv . $ciphertext; # encode the resulting cipher text so it can be represented by a string $ciphertext_base64 = base64_encode($ciphertext); //echo $ciphertext_base64 . "\n"; return $ciphertext_base64;
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Using $this when not in object context in /in/62q4O:3 Stack trace: #0 {main} thrown in /in/62q4O on line 3
Process exited with code 255.
Output for 5.0.0 - 5.6.28
Fatal error: Using $this when not in object context in /in/62q4O on line 3
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: mcrypt_get_iv_size() in /in/62q4O on line 16
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: mcrypt_get_iv_size() in /in/62q4O on line 16
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: mcrypt_get_iv_size() in /in/62q4O on line 16