3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php error_reporting(1); ini_set('display_errors', 1); class Encryption { private $key; protected $iv_size; protected $iv; public function __construct() { # --- ENCRYPTION --- # the key should be random binary, use scrypt, bcrypt or PBKDF2 to # convert a string into a key # key is specified using hexadecimal $this->key = pack("H*", "myKeyIsGreaterth2nanndbestofall04nkdsdffsd546754sdfvsdg6efflsdfs"); # create a random IV to use with CBC encoding $this->iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $this->iv = mcrypt_create_iv($this->iv_size, MCRYPT_RAND); } public function encryptData($input) { $output = $this->encrypt($input); return $output; } public function decryptData($input) { $input = base64_decode($input); $output = $this->decrypt($input); return $output; } protected function decrypt($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; } protected function encrypt($string) { # 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) $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); # === WARNING === # Resulting cipher text has no integrity or authenticity added # and is not protected against padding oracle attacks. return $output; } } $test = new Encryption(); $encrypted = $test->encryptData("Vicky"); echo "This is encrypted text of a string Vicky $encrypted \n"; echo "This is decrypted text ".$test->decryptData($encrypted);
based on MnJGQ
Output for 7.0.20 - 7.2.0
Fatal error: Uncaught Error: Call to undefined function mcrypt_get_iv_size() in /in/l187L:19 Stack trace: #0 /in/l187L(70): Encryption->__construct() #1 {main} thrown in /in/l187L on line 19
Process exited with code 255.
Output for hhvm-3.10.1
This is encrypted text of a string Vicky gqWeqkH5KUGt48wr5UoU+facl+nc2uNbMXhA+0x7h/w= This is decrypted text Vicky
Output for 5.0.0 - 5.3.29, 5.6.0 - 5.6.16
Fatal error: Call to undefined function mcrypt_get_iv_size() in /in/l187L on line 19
Process exited with code 255.
Output for 5.5.30
This is encrypted text of a string Vicky cptOLJnctIxwHRBCSNpdWBO0GIXX9gy2EckcpzRv8nE= This is decrypted text Vicky
Output for 5.5.29
This is encrypted text of a string Vicky hwkpVB9ajxC2Tvmh2XinFosPCMofHea5ojr0itibF/k= This is decrypted text Vicky
Output for 5.5.28
This is encrypted text of a string Vicky XJmtQy+Qx2lTtHsmHULLDctpRJWJWQAHk7PW/2arzC0= This is decrypted text Vicky
Output for 5.5.27
This is encrypted text of a string Vicky Lq1PeZWUchS9V7hexL1dk9xxhNOXs44bTqXKwqllcmQ= This is decrypted text Vicky
Output for 5.5.26
This is encrypted text of a string Vicky E7LSqKqepSLlesA4vymWlDHjOFfH3n+G47N79xUwpw8= This is decrypted text Vicky
Output for 5.5.25
This is encrypted text of a string Vicky oG61gPnLNJzCjoRTgAZh02E60uosDzeADWk10Zz/M3g= This is decrypted text Vicky
Output for 5.5.24
This is encrypted text of a string Vicky dYnfQBbT1M3cWVtGuf6K8laFm+H+gSX11y4wWw1D64U= This is decrypted text Vicky
Output for 5.5.23
This is encrypted text of a string Vicky 98+MuHJKdcEUMWl5SGqjahUAw/bRaF3MY8Dq8bzMW8E= This is decrypted text Vicky
Output for 5.5.22
This is encrypted text of a string Vicky KTb7rvhRdpx6Mr71ODkvFl+Lfvuz5823xsOZ0+JpEzs= This is decrypted text Vicky
Output for 5.5.21
This is encrypted text of a string Vicky OmLinhS1HHy6JnKPQ+dfjFHuLlNNu1b9oNF5xi9fhr4= This is decrypted text Vicky
Output for 5.5.20
This is encrypted text of a string Vicky qeUbMBOKNGWnQERIXl5yHWSG9XbK7EPktPYTkyKnK/Y= This is decrypted text Vicky
Output for 5.5.19
This is encrypted text of a string Vicky JVOHq9tvH5KWPNLiWr4BFRjZpoaoanqQzjH5dIzE6jE= This is decrypted text Vicky
Output for 5.5.18
This is encrypted text of a string Vicky o/kn4GqeE95YFfgUDZTfe14oFNO/ITAVcQD8lOEQFYg= This is decrypted text Vicky
Output for 5.5.16
This is encrypted text of a string Vicky zxf95hm1yyPtdVHYoZ7LghfE2E3rgpOGX/ruUmJevaI= This is decrypted text Vicky
Output for 5.5.15
This is encrypted text of a string Vicky QXq+lfJeWqYNhwDOzfkwlUP9B2TRFQnS3BeqFmAkhDs= This is decrypted text Vicky
Output for 5.5.14
This is encrypted text of a string Vicky LpeAwTVdlI8ydtRbMYlLD09kwo7it/h2RmPO9fG8JIs= This is decrypted text Vicky
Output for 5.5.13
This is encrypted text of a string Vicky jplXWkuR0gS1xAnKNMWTI5BoS9tlFi2pP50wpWL1/0I= This is decrypted text Vicky
Output for 5.5.12
This is encrypted text of a string Vicky ciS7vjVESbKKaqQ/dFOyEFOhVMx6evKyUDY+J+T7FZM= This is decrypted text Vicky
Output for 5.5.11
This is encrypted text of a string Vicky ba0XuhP0OwMoziQHrEK0Gz+MaarAgKlu6uQus5k3SaE= This is decrypted text Vicky
Output for 5.5.10
This is encrypted text of a string Vicky 51xS35euibyVErzO6kB9uu9uXiqFI/w8qTFmPnxYT4o= This is decrypted text Vicky
Output for 5.5.9
This is encrypted text of a string Vicky Pk7sem+wfs+q6Z7tALkVCFqiGhjSCreR2xZHRNiZuQg= This is decrypted text Vicky
Output for 5.5.8
This is encrypted text of a string Vicky MckKUwLYbhTg7GvmJGbe4ZNMopo28zYiU27ZAvkH4Pw= This is decrypted text Vicky
Output for 5.5.7
This is encrypted text of a string Vicky Fy+Bn7kkK8folF5xZFlowFkasvVg5erNNCp/5lALgIg= This is decrypted text Vicky
Output for 5.5.6
This is encrypted text of a string Vicky sz1QmJGFXlm5OLmE+uy2YVsLtXmQ6quQ5/ZVJjgW6Ng= This is decrypted text Vicky
Output for 5.5.5
This is encrypted text of a string Vicky XWmj7bOtColmcF9YUbczfoFB7hLSHVhlEuy4mCzE6tc= This is decrypted text Vicky
Output for 5.5.4
This is encrypted text of a string Vicky wd9VqHEzIFm8XFvg8QMh3XhMoXoouNnfdFwUjZg7g8E= This is decrypted text Vicky
Output for 5.5.3
This is encrypted text of a string Vicky iCNnppy2ZLqVyJpfhcdLrg2clS0YJ95kd4/ZvbkIZQ0= This is decrypted text Vicky
Output for 5.5.2
This is encrypted text of a string Vicky WmCTKBbUz1s74zZK2jHjCFqSaAhKfgIeKc+FEEiGsuA= This is decrypted text Vicky
Output for 5.5.1
This is encrypted text of a string Vicky tYRdQTPqbEQWSUkWOe554xSqUUpIOuCzjjxMeDsfJsk= This is decrypted text Vicky
Output for 5.5.0
This is encrypted text of a string Vicky 49rWttpWeW7torsDfwKfAz5f8HxeuQvnCVB4xcLQSbo= This is decrypted text Vicky
Output for 5.4.45
This is encrypted text of a string Vicky xSS/SecpuKvl+w2yxVksdx++0GJaGYxwoi8pEN0OyZ4= This is decrypted text Vicky
Output for 5.4.44
This is encrypted text of a string Vicky vjhwfusRWivWEdpQlU7acqSv8cCjX/CiW/I41BjtZpI= This is decrypted text Vicky
Output for 5.4.43
This is encrypted text of a string Vicky g7yvN6jZ0NWbw37YUg5GDuzXdRWkNciBDWgH65H1ptQ= This is decrypted text Vicky
Output for 5.4.42
This is encrypted text of a string Vicky qFx8br5CpIToRbzp+etVP4Xabv6EHsYTmh896eO/05I= This is decrypted text Vicky
Output for 5.4.41
This is encrypted text of a string Vicky kU/kyu3IplYNVDbahdXXAN3NvaXQ4X61OW7lXDwDA80= This is decrypted text Vicky
Output for 5.4.40
This is encrypted text of a string Vicky NQXu4mUFdJsZ6FIuX0s/j0QkGFrYaCqUsgjOzeNPR0U= This is decrypted text Vicky
Output for 5.4.39
This is encrypted text of a string Vicky 1U9lca3+Ws87can3A3S6I1/IQnKWXQYVgJ2lTZJCSnk= This is decrypted text Vicky
Output for 5.4.38
This is encrypted text of a string Vicky 2A1jnxWkGLLMdANFNo/JiapEpn7EKO1vDjbji8mWAC4= This is decrypted text Vicky
Output for 5.4.37
This is encrypted text of a string Vicky Nv5gSln9GH8oZvhBiIYu23W5B8zD20hGGHP+2vU2G6w= This is decrypted text Vicky
Output for 5.4.36
This is encrypted text of a string Vicky 2W5x3xCx4mIKhGJFKXY4Zsi7/zvQzQ5QHelyvUdH2SY= This is decrypted text Vicky
Output for 5.4.35
This is encrypted text of a string Vicky Kee064ylF2vISmGKkd08MYvWIdo+nJYCf8xku3n5gLU= This is decrypted text Vicky
Output for 5.4.34
This is encrypted text of a string Vicky QHJ0dHockseQQTvHV5uUBSr3oTn4JjNU81IMfgyb66Q= This is decrypted text Vicky
Output for 5.4.32
This is encrypted text of a string Vicky T6Tjqr8QiMhJ1JduHO/kafujeOGzuz5DaKliHJwRCLw= This is decrypted text Vicky
Output for 5.4.31
This is encrypted text of a string Vicky 0IP0nEPiNGDXY3m/Xe9xcc/bb0x+bYK+OncsiVhV9zs= This is decrypted text Vicky
Output for 5.4.30
This is encrypted text of a string Vicky XCPxT7St5njIhX1vD5RC2o7a/RPXqey2PLwo+TWw+i0= This is decrypted text Vicky
Output for 5.4.29
This is encrypted text of a string Vicky Bx1E14dnTrtGrArag4nH0aMYZYMQGXPIiqU3rh6wyUQ= This is decrypted text Vicky
Output for 5.4.28
This is encrypted text of a string Vicky 9kPYK669RbX2bE0NGNHEFqZhGD86THkBhYEtNaV2Lpc= This is decrypted text Vicky
Output for 5.4.27
This is encrypted text of a string Vicky WTOOmuGGrVvMkB/6kG6ApBnEqms1IzrCb4wP63dfw4Q= This is decrypted text Vicky
Output for 5.4.26
This is encrypted text of a string Vicky 6ZlHJQNFblhYwWl8J/u2oWkFAYFvw5Se8ebc5Zx0+MY= This is decrypted text Vicky
Output for 5.4.25
This is encrypted text of a string Vicky PtsFyIervaEzrCU0E0xDKvNzM+mSOYZWmPP7y/1RgKM= This is decrypted text Vicky
Output for 5.4.24
This is encrypted text of a string Vicky qQJIoIJndmBXHwa8kGm1qHoQ5qO6qEvNsFBn4sf9cPE= This is decrypted text Vicky
Output for 5.4.23
This is encrypted text of a string Vicky /KI20dX6ruLiYZ4FaujmRNFpBxRWs4X0Mmeec31TBkk= This is decrypted text Vicky
Output for 5.4.22
This is encrypted text of a string Vicky jzuz3V3oOZhszfZHOtNFQKFC+L8+HQ6sX/TAcH/nj1M= This is decrypted text Vicky
Output for 5.4.21
This is encrypted text of a string Vicky xzkNgBGj5CVeHx5fYxi6ic1ApG2T856UZqf7/f4gymU= This is decrypted text Vicky
Output for 5.4.20
This is encrypted text of a string Vicky 7Ay+zyjycdwYJ0Zo/oUqIJonTPsktKo3KKbH03ixM4E= This is decrypted text Vicky
Output for 5.4.19
This is encrypted text of a string Vicky Dz3zge+Ws/s2WjnlNJL0uT0Lj6GsV0VeQPwzeOgyr1M= This is decrypted text Vicky
Output for 5.4.18
This is encrypted text of a string Vicky N56tj484C8yOdvgxsxV2dv58aLUISqjY+edYWPf33kw= This is decrypted text Vicky
Output for 5.4.17
This is encrypted text of a string Vicky SepLO+xglqk4I5y3IdTcnU+BoKxUKFN041gyAhvQn2Y= This is decrypted text Vicky
Output for 5.4.16
This is encrypted text of a string Vicky PSEaeyQf18L9Pbton5AdwB0md17gBh0h8s8KcroleUM= This is decrypted text Vicky
Output for 5.4.15
This is encrypted text of a string Vicky 4EJf7TSS/eztCw2J44ymtsDXZPaOJ79UzG4nWr7/70I= This is decrypted text Vicky
Output for 5.4.14
This is encrypted text of a string Vicky 8QMaQnFf63srT1FB5zb3LbDGntECmlJlJzCBj3DJb1g= This is decrypted text Vicky
Output for 5.4.13
This is encrypted text of a string Vicky qw6yvH5cPfvZSEOCBASakxy7cJBi7KiMwE/4kACI1Y8= This is decrypted text Vicky
Output for 5.4.12
This is encrypted text of a string Vicky DIpsECCPx1/E5AfVMqhAT0qOvmtNVLwsna0MD8lkVvg= This is decrypted text Vicky
Output for 5.4.11
This is encrypted text of a string Vicky yirI/ivvAKZj9KM9FkBuuLkg8RPITP+cxbv+Umok2OQ= This is decrypted text Vicky
Output for 5.4.10
This is encrypted text of a string Vicky JGrnDx/hqTTJDioozFj6DlIeVj5IiePEM5ojCsgRnjY= This is decrypted text Vicky
Output for 5.4.9
This is encrypted text of a string Vicky T3WC31szCeO6qQekznmP4HEOnDb5h7SJu9hjPGOI0j4= This is decrypted text Vicky
Output for 5.4.8
This is encrypted text of a string Vicky 5Nx9Mn1clyJEHjAy2atsMiM+cyVlhGOZKjExXjU4FA8= This is decrypted text Vicky
Output for 5.4.7
This is encrypted text of a string Vicky /B5HjiewHuGSY7jFA4Nzx2jtqdlrCTNqc9ZgtOFYcjY= This is decrypted text Vicky
Output for 5.4.6
This is encrypted text of a string Vicky C+QVFugJuRpTV2UipfFkTlW1gTVHOCB9aQN/4E2QlWI= This is decrypted text Vicky
Output for 5.4.5
This is encrypted text of a string Vicky odT1TFFyCUchNXj8G+vjKIX3XUKCajH2/4ktCvCWriM= This is decrypted text Vicky
Output for 5.4.4
This is encrypted text of a string Vicky +Ic2grlsbySRt/iflbz6zf+hdJ70QbmCcS2/UagDg7k= This is decrypted text Vicky
Output for 5.4.3
This is encrypted text of a string Vicky edi5KYqzBdvzsEPO9MZDPKw95vxKt4l+AXZlYU3GOw8= This is decrypted text Vicky
Output for 5.4.2
This is encrypted text of a string Vicky TFzS9LG958Svf+dTNNlaSLyhoVSPL7jrI4kxXi2rJJ4= This is decrypted text Vicky
Output for 5.4.1
This is encrypted text of a string Vicky Cvq3smHmHN60aziIwf02AoumD1KTWdAW8sHdASSE2vk= This is decrypted text Vicky
Output for 5.4.0
This is encrypted text of a string Vicky GVLc5Fjz2i2xC8ns5Axupxf+tDREiBpu2sJWEWvysVA= This is decrypted text Vicky
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/l187L on line 8
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/l187L on line 8
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/l187L on line 8
Process exited with code 255.