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; } public 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; } public 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("Narendra"); echo "This is encrypted text of a string Narendra$encrypted \n"; echo "This is decrypted text ".$test->decryptData($encrypted);
based on 8gbkM
Output for 7.0.6 - 7.3.0alpha1
Fatal error: Uncaught Error: Call to undefined function mcrypt_get_iv_size() in /in/P3Mor:19 Stack trace: #0 /in/P3Mor(70): Encryption->__construct() #1 {main} thrown in /in/P3Mor on line 19
Process exited with code 255.
Output for 7.0.5
This is encrypted text of a string Narendra5SHD2D7kDF9KZEUwgtmB2rHU99KGoCPMpAQOb+wOHE4= This is decrypted text Narendra
Output for 7.0.4
This is encrypted text of a string Narendranc4QUdEEQq9OgZwEBh1qUEg3oljYEJTdnBwAhid36Ko= This is decrypted text Narendra
Output for 7.0.3
This is encrypted text of a string NarendraZ7ll/nkCSL/1mGyEQgHDBTN2jxTzsqegxs3BSdwgDuM= This is decrypted text Narendra
Output for 7.0.2
This is encrypted text of a string Narendra68iT8jxYrWMlI3gasWu+XZOxu5SeX4FzT01ZlH9ByDA= This is decrypted text Narendra
Output for 7.0.1
This is encrypted text of a string NarendraMeEETTopPUPCm/Fy52vqEap/rEIcQF+1bIlpd0Fu86o= This is decrypted text Narendra
Output for 7.0.0
This is encrypted text of a string NarendrawXUU3fx2pyHscZ5ogVbGvjR83nvLLt1PEydSJLX8A1Q= This is decrypted text Narendra
Output for 5.3.20 - 5.3.29, 5.5.35, 5.6.21 - 5.6.28
Fatal error: Call to undefined function mcrypt_get_iv_size() in /in/P3Mor on line 19
Process exited with code 255.
Output for 5.6.20
This is encrypted text of a string NarendraFFmQ8vIwlbomV/IMOGjRm/CxHdQHC6Fs2U9ND7gOiSE= This is decrypted text Narendra
Output for 5.6.19
This is encrypted text of a string NarendraZz858qNCplNT6Rsu4Hbbi5rEEil9z2BqFMrrHfXTyqw= This is decrypted text Narendra
Output for 5.6.18
This is encrypted text of a string NarendraZSFbqM/vhObveTiEnNLSIHDM1lnwV9AVy4rs1BDBwFw= This is decrypted text Narendra
Output for 5.6.17
This is encrypted text of a string Narendra3JPFJcLWcfugjFee6T9oxo3oq+wsZU0X7l7RQwcwhTI= This is decrypted text Narendra
Output for 5.6.16
This is encrypted text of a string NarendrabKYoj8AU0Gv8tfXWVbhoAs7qvx0FUq0v+k1hhOJnmVk= This is decrypted text Narendra
Output for 5.6.15
This is encrypted text of a string Narendray9dej4SE6QvHjBthCztv1ZCMLlNS29TcJWY040JWpsI= This is decrypted text Narendra
Output for 5.6.14
This is encrypted text of a string Narendra749tW4HrVWeQLVGSpCLbPiqPHtmA6aJoQAGl+BJbW9o= This is decrypted text Narendra
Output for 5.6.13
This is encrypted text of a string Narendra/lMfqHHMEa5IG47LlmSTM8CntSoAoASSmE0gtgpqpxk= This is decrypted text Narendra
Output for 5.6.12
This is encrypted text of a string NarendraBn9FlexNAqwvwiwH8ZRxWNOHznUwSFqrrijKTVi5120= This is decrypted text Narendra
Output for 5.6.11
This is encrypted text of a string NarendraV+2C9ORYLOaN15wYHlMoIVIZt+tcQZEFvY4WECHe+t4= This is decrypted text Narendra
Output for 5.6.10
This is encrypted text of a string NarendraicjaRP1BharMwuhcZ1313lD8N8spKgWqEiqMX7+Bm60= This is decrypted text Narendra
Output for 5.6.9
This is encrypted text of a string Narendra9ULTXZ1vkwN3ur+iZzFOUSOaZ4/rP38Te/DYUYzHLhg= This is decrypted text Narendra
Output for 5.6.8
This is encrypted text of a string NarendraOPoACZI3gUoztOQdb/mFgTdSmbrM4GbxcZoaRf0507c= This is decrypted text Narendra
Output for 5.5.34
This is encrypted text of a string NarendrarQCcLqs1qlLRjyaaomF6apsq02bvtn5GVXLtL136vP4= This is decrypted text Narendra
Output for 5.5.33
This is encrypted text of a string NarendraGJFWXz2ucLcJvUSjDzKQW/564Cu2VuW+jgJUyxYXoto= This is decrypted text Narendra
Output for 5.5.32
This is encrypted text of a string NarendracVE13AryKU5C2P6QM/rOMcoY+t3M1y1pgpPnfzKWBzs= This is decrypted text Narendra
Output for 5.5.31
This is encrypted text of a string NarendraKQGaWaMBQqkx4Kc+2alg44Q9J0ZXPLWHwhEr0bUZW50= This is decrypted text Narendra
Output for 5.5.30
This is encrypted text of a string NarendrazGaRXAGwwyXbS3yQ7ycFUvDaw1L5rRFdT8q02jfax7g= This is decrypted text Narendra
Output for 5.5.29
This is encrypted text of a string NarendraF5YUQesz9M/APEHV70lAVrA/atyeMRCohDFcfWV8T8s= This is decrypted text Narendra
Output for 5.5.28
This is encrypted text of a string NarendraY1MY0mrii3MRCseoOjW21jQM9U1s8yIFmvB8NDaEzMI= This is decrypted text Narendra
Output for 5.5.27
This is encrypted text of a string NarendraFOTR2xgdVMSzDCSFNpXUjN3tnhS53CRXSt50o7x5/yQ= This is decrypted text Narendra
Output for 5.5.26
This is encrypted text of a string Narendra6PQOngvbKHOeIkpvdZxn41EPbeFvY4yPKmS643gxY1M= This is decrypted text Narendra
Output for 5.5.25
This is encrypted text of a string NarendraIzg+ZB2ISKC/df1CNx6AjNnhACUkG9ctx7LoR2ceaOo= This is decrypted text Narendra
Output for 5.5.24
This is encrypted text of a string Narendra6+340jgduUn1LMlgpXbhB1gnQBpozo6zNn/zd4vcbCQ= This is decrypted text Narendra
Output for 5.4.45
This is encrypted text of a string NarendraFj4M+8nCPa9LrwPZrRL2mhDQsdwZCeOOEdj0LSOSlVQ= This is decrypted text Narendra
Output for 5.4.44
This is encrypted text of a string NarendraRyBfQucXdLVROgs4Wulal7Ed1Oiog4BdtzELgQZR75M= This is decrypted text Narendra
Output for 5.4.43
This is encrypted text of a string NarendraAzjc52h+rx+BvHTffzvGb3ApyJa6+abEmwn/TIqbrFc= This is decrypted text Narendra
Output for 5.4.42
This is encrypted text of a string NarendraqLuDI3C7Uuky9a5zP6KirAEl2nYtVkrEjWu3iE/JE20= This is decrypted text Narendra
Output for 5.4.41
This is encrypted text of a string Narendraruuhn2HOxo7q7XqVnWu1D+3mrbz8+zDxTj0iwLPiNOY= This is decrypted text Narendra
Output for 5.4.40
This is encrypted text of a string Narendrauh8TVwqSEDgt4Lo0m9WA9SiUUFA78v+rXxXKpca2xBs= This is decrypted text Narendra
Output for 5.4.39
This is encrypted text of a string NarendraNHidMG2ZkWNVkPK4wF0I97nhrzyMn7dRLjPlfg15X5E= This is decrypted text Narendra
Output for 5.4.38
This is encrypted text of a string NarendraSrlixSC5c5e7XNHSINnJqGq9eM16+v4gqjs2u4z+2f0= This is decrypted text Narendra
Output for 5.4.37
This is encrypted text of a string NarendraQGjFtySrsPfDOHNyrfFN47Nvq5YDWrcX+AoQDFlar/0= This is decrypted text Narendra
Output for 5.4.36
This is encrypted text of a string NarendraluQai4sLi7Rz8gd61D4OyqvyZnpnrJ69fvWkEykRizQ= This is decrypted text Narendra
Output for 5.4.35
This is encrypted text of a string NarendragfOz4igeFEizWA8nLsA+ve8gamBdsVWBI4XmE1YI6Kg= This is decrypted text Narendra
Output for 5.4.34
This is encrypted text of a string Narendraub/UQb9BbdHOgZWwHshhIPbYJrE6mAWa0fTK2/b+e58= This is decrypted text Narendra
Output for 5.4.32
This is encrypted text of a string Narendra6RD7SNJMdNVzDrWvC3VAAULi/bPGiHrHIrGIw0tweUI= This is decrypted text Narendra
Output for 5.4.31
This is encrypted text of a string NarendraFQRy9hcICRmzk0XzrTUW6K7lhmxGEbTzz6fh6AgVCOo= This is decrypted text Narendra
Output for 5.4.30
This is encrypted text of a string NarendragDwh5Cg/87xP7qjA+THyYeluxqJ/lCysIUnvyiwRKxg= This is decrypted text Narendra
Output for 5.4.29
This is encrypted text of a string NarendramCtnKRRbqAeRCWJsc3PXoN34GNnX9WWj4oBDJ7B2NRY= This is decrypted text Narendra
Output for 5.4.28
This is encrypted text of a string NarendraZ6iBqHT0Uyb55yEHib51+fmOkEBzKHfYEUhWkozYZU8= This is decrypted text Narendra
Output for 5.4.27
This is encrypted text of a string Narendra4hNGdVZduKU9WLchT4/JA+c31bbLV16jDFU4O4jMJAg= This is decrypted text Narendra
Output for 5.4.26
This is encrypted text of a string NarendraSOT+u1wklh28NiLzSl9MQHnINDCj0AHbOcUxOAynfkU= This is decrypted text Narendra
Output for 5.4.25
This is encrypted text of a string NarendraCc+P5EcOk1LUmHk7/TNWYv9Quo3ImAoLrVmG9h65U7U= This is decrypted text Narendra
Output for 5.4.24
This is encrypted text of a string Narendra0Pu3dOyst7zWBDSkdNQq/MWwqf9M6w4Gu0ZMo2k1RJ0= This is decrypted text Narendra
Output for 5.4.23
This is encrypted text of a string NarendrahcpqfXKUbSQ82dIeDh8OsLPdCPUkjG+3vo2zYqsS5S0= This is decrypted text Narendra
Output for 5.4.22
This is encrypted text of a string Narendra+S0UPfrJPbMp8PRU0DRA3U1G1mNhymsqR/jn+e49ZnA= This is decrypted text Narendra
Output for 5.4.21
This is encrypted text of a string Narendrawnn279WWXoY7j35gUQTs1roxzbwSzxPHgQXaln4kAOg= This is decrypted text Narendra
Output for 5.4.20
This is encrypted text of a string Narendra1hxwwLJInG1cyrPLdo8xzzNoyV6eP2sOAY11IQBaXaw= This is decrypted text Narendra
Output for 5.4.19
This is encrypted text of a string NarendraNvV/6TYycCoyfWKDMJTb9mCVeHPvUHwHYuHhuyE1tcc= This is decrypted text Narendra
Output for 5.4.18
This is encrypted text of a string NarendraHXUdfF87+VlY6ebmnmqH+zxo/UAxDSlhhEeLPTbNQBg= This is decrypted text Narendra
Output for 5.4.17
This is encrypted text of a string NarendraKx1Dc3TfEvbpRku0OaGhFElWPEaVMx5MJSi7xnen29U= This is decrypted text Narendra
Output for 5.4.16
This is encrypted text of a string Narendra+rHaqnvTdRBywQYfuIRXQdhI1GyRWaLwMS563hjAx0M= This is decrypted text Narendra
Output for 5.4.15
This is encrypted text of a string NarendraIVJR6DPIF6Q5bRyii1Lyg0Hb3tCVkMpdGRpsXGLJuk0= This is decrypted text Narendra
Output for 5.4.14
This is encrypted text of a string NarendrahttYbce7Q+xpHNYgLEvFxxVYZFaNqzsxqPpY+ylN28M= This is decrypted text Narendra
Output for 5.4.13
This is encrypted text of a string Narendra8vWABdATXJnRlE18rn2UthuTQXVRSFQonNNQ2OH+h7M= This is decrypted text Narendra
Output for 5.4.12
This is encrypted text of a string NarendrapHwHh1CKPCJj4RxNtcPxeYQDCgesE6JeIPKt84BjOA8= This is decrypted text Narendra
Output for 5.4.11
This is encrypted text of a string NarendrafszDz6/fbJ70NarT/L3uXLFkWKHNuk6E2DLykT7E4UM= This is decrypted text Narendra
Output for 5.4.10
This is encrypted text of a string NarendraqdJVu1E0yfcOdsCKELkM6bp+HZF1V03gDQI0yS/4UHY= This is decrypted text Narendra