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("Narendra"); echo "This is encrypted text of a string Narendra $encrypted \n"; echo "This is decrypted text ".$test->decryptData($encrypted);
based on HRI03
Output for 7.0.6 - 7.2.0
Fatal error: Uncaught Error: Call to undefined function mcrypt_get_iv_size() in /in/MnJGQ:19 Stack trace: #0 /in/MnJGQ(70): Encryption->__construct() #1 {main} thrown in /in/MnJGQ on line 19
Process exited with code 255.
Output for 7.0.5
This is encrypted text of a string Narendra 8Z0q7n44RWMpy2N/EyILfGT6TyMy56PUybGUx6/EAS0= This is decrypted text Narendra
Output for 7.0.4
This is encrypted text of a string Narendra sJMT54OlePMXAGAnyLEafS5cntc1JiH3BGajP1X3ASw= This is decrypted text Narendra
Output for 7.0.3
This is encrypted text of a string Narendra YecBnxPdPFl3JeRhuYI1Wketz42kI6A8bSTy4q+FKNE= This is decrypted text Narendra
Output for 7.0.2
This is encrypted text of a string Narendra GgGm/bbEYTTDi0n+DZGmKbn9KxC28WW+hguBWoYDYDM= This is decrypted text Narendra
Output for 7.0.1
This is encrypted text of a string Narendra jIp478ucO/ko4WeAHR4BgOeTWqMd9egyK3qMiqsn5lE= This is decrypted text Narendra
Output for 7.0.0
This is encrypted text of a string Narendra rPrrHwpKERJr+YBK2h7a9j4rE2NV79P3lnIhJJh7R8U= 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/MnJGQ on line 19
Process exited with code 255.
Output for 5.6.20
This is encrypted text of a string Narendra qCX4Q8Hpg33QS2oxMota0C2OIIJXgG81lejN4l3YSOE= This is decrypted text Narendra
Output for 5.6.19
This is encrypted text of a string Narendra j2afIxgxDBVW25gS/hqIIQrr1/aqUEsltnefanineL4= This is decrypted text Narendra
Output for 5.6.18
This is encrypted text of a string Narendra z0YoDA4whWDq3YB2CCuuU8j/COkT4qIHlDxWT9dZ5aU= This is decrypted text Narendra
Output for 5.6.17
This is encrypted text of a string Narendra jKu+yCJMH0uQ1i4GnWLIvZNgTLRKExgkyq7j93eQKgs= This is decrypted text Narendra
Output for 5.6.16
This is encrypted text of a string Narendra 7EXGvHUoR0kgdoQorHUffoEgb6x3PXMLHopJaz/Gy94= This is decrypted text Narendra
Output for 5.6.15
This is encrypted text of a string Narendra DBqrvG5Ou/a5couhXmF6ys5FqgXdZAj/bPz2vPZKv+w= This is decrypted text Narendra
Output for 5.6.14
This is encrypted text of a string Narendra Ss5Noktg2/tlWnzV1QJbvorNVchPFzPExT4UnZconi0= This is decrypted text Narendra
Output for 5.6.13
This is encrypted text of a string Narendra 2nHGqNGfo+SOSEekV1cTgEyMdQPYph9zexbjYH0BQ4Y= This is decrypted text Narendra
Output for 5.6.12
This is encrypted text of a string Narendra YQkzNO6i/QG5nwNJA2RhVuCwJgy0Lmh/JHSCrzw0nPM= This is decrypted text Narendra
Output for 5.6.11
This is encrypted text of a string Narendra lB+201btKlglOGc3bBnbmcE5sTChYGuw0eYRVit+SR8= This is decrypted text Narendra
Output for 5.6.10
This is encrypted text of a string Narendra h9NlZiUMoH1uToqlfL7m61CFnMyJ425f1G9ukZeoM7U= This is decrypted text Narendra
Output for 5.6.9
This is encrypted text of a string Narendra 0Dxj3C3JEz+PuqECP0SsHP8m+OYOPoXNjW+CqpzNkHY= This is decrypted text Narendra
Output for 5.6.8
This is encrypted text of a string Narendra P3FKMcSCKwuoH+qCfiovb8FzWR8pAu/fX8HLM4v0Uks= This is decrypted text Narendra
Output for 5.5.34
This is encrypted text of a string Narendra 6WW9cVyv1wEDDD67c1IwQ3WUcGi7EnuLlEC0BZUK+Dw= This is decrypted text Narendra
Output for 5.5.33
This is encrypted text of a string Narendra AvfQKL7jAJ5OmG4tCzHX5Yb+vkZBid7uyLyofWxdE/A= This is decrypted text Narendra
Output for 5.5.32
This is encrypted text of a string Narendra 2X8gjn+T2GQpkHFAYPAI64GOxlKHH46TXVXuxCsAVm4= This is decrypted text Narendra
Output for 5.5.31
This is encrypted text of a string Narendra ApDFNID466itmWbL0u9270ygtD+YaIyJ7QIQBLI0uBU= This is decrypted text Narendra
Output for 5.5.30
This is encrypted text of a string Narendra GlsTnVemxp5rO05uydkJwIsxLGn+NBR09MqGsA77/mk= This is decrypted text Narendra
Output for 5.5.29
This is encrypted text of a string Narendra eCeymJSstFczCHA5KM8MSJM8jEES168R2AoFGgxQYqc= This is decrypted text Narendra
Output for 5.5.28
This is encrypted text of a string Narendra ZQwF10yHscTwTW5k8Ke+cCF+durD03HA6wgAvzLd1cs= This is decrypted text Narendra
Output for 5.5.27
This is encrypted text of a string Narendra RZ1GuNSHK2/h0ygEVadnf5aGek4/17dSW80jSyUIYPE= This is decrypted text Narendra
Output for 5.5.26
This is encrypted text of a string Narendra T0cDBzeHyI4nUiq0PSziXen73fbpHx9cFriX6QVrQkA= This is decrypted text Narendra
Output for 5.5.25
This is encrypted text of a string Narendra HG5noF8dvX99XiHM0RAqfbuYrwnSncEr3gQycJIXh78= This is decrypted text Narendra
Output for 5.5.24
This is encrypted text of a string Narendra qA7aGjyNZ6otfx+nYiH4bLEaEBfECr4R4w/66LcD2Sc= This is decrypted text Narendra
Output for 5.4.45
This is encrypted text of a string Narendra O2Wci+tSKj01yB0ZyXl+7kFlBNcFVk4K7CPlHH3x8Ug= This is decrypted text Narendra
Output for 5.4.44
This is encrypted text of a string Narendra 41vG4DtJdY3yJX+yeal5P27KCqeYOL/4WMj6J1b4SD8= This is decrypted text Narendra
Output for 5.4.43
This is encrypted text of a string Narendra Yq+s8yb9HGBJwqLCBti/7tyWxu6KOdKVnoHfQ/nfo0c= This is decrypted text Narendra
Output for 5.4.42
This is encrypted text of a string Narendra /nMvfUpp9O7q2JLGfevjeaSQfsbEA02Ag1rRZY6l6d8= This is decrypted text Narendra
Output for 5.4.41
This is encrypted text of a string Narendra 4J8bvMshjrHp8pNEzzD9WrrML1R59oWY7GdLtZXTF7w= This is decrypted text Narendra
Output for 5.4.40
This is encrypted text of a string Narendra jt6rzPdPbcDMsZmVHVAYhXnzFNxDZ9okcDednFuwJII= This is decrypted text Narendra
Output for 5.4.39
This is encrypted text of a string Narendra sDfdHHEa3VtCxudJHS8TbR2AzIyVrLuApWQ6N8kgdY4= This is decrypted text Narendra
Output for 5.4.38
This is encrypted text of a string Narendra mxj28KQx2WVNCt3H/E8XDE/8+65eoSHBqgA+rkxrw50= This is decrypted text Narendra
Output for 5.4.37
This is encrypted text of a string Narendra g+PJJuIU6xOi+IWPuqWcN81FWk8ADITLvYlRCHH/usc= This is decrypted text Narendra
Output for 5.4.36
This is encrypted text of a string Narendra a00vYuPVmJ24nZsQT342m+CcBItiSv4FscbYhcIOkjs= This is decrypted text Narendra
Output for 5.4.35
This is encrypted text of a string Narendra kr11T/n7m15NmeERu7eFixi2h7jSu3eblvuYK/fnPFk= This is decrypted text Narendra
Output for 5.4.34
This is encrypted text of a string Narendra XFMcXvceE7VLodEqv6mAVJpTPr7u5s8v3pfv8Q+m2uY= This is decrypted text Narendra
Output for 5.4.32
This is encrypted text of a string Narendra 3gWPIMMgVsl3Q35sq7R79DK/IslouDlir/quLs4aJm8= This is decrypted text Narendra
Output for 5.4.31
This is encrypted text of a string Narendra vXWnMvJky0hS4Lv9+oTV5FZ1wSr6n3qbYNnD/I0+cp8= This is decrypted text Narendra
Output for 5.4.30
This is encrypted text of a string Narendra /ZQYttBPMiEpX3WZ+HnfElcJW4nHU7okwI70mwigkEw= This is decrypted text Narendra
Output for 5.4.29
This is encrypted text of a string Narendra fiVaAzWXc+khgDu10oIh6iSiJWhHSgZKd8RjfcOT5aw= This is decrypted text Narendra
Output for 5.4.28
This is encrypted text of a string Narendra hJNOzHGCjB9XwFZiuLUKRAnNld1Pb96FIrCpt4r87gE= This is decrypted text Narendra
Output for 5.4.27
This is encrypted text of a string Narendra YcCgPSnRg5g4n6OGpoXdcjXdkkpde2thVPRLWixEoyM= This is decrypted text Narendra
Output for 5.4.26
This is encrypted text of a string Narendra Y8Hc6hzZGCNnz3bbs00JqYvLKUwaKmj92RATo/l0ZuA= This is decrypted text Narendra
Output for 5.4.25
This is encrypted text of a string Narendra rkmNbgtbqeOOTiuPjCqhKyyYopu4HkcPO+B42p1BgcE= This is decrypted text Narendra
Output for 5.4.24
This is encrypted text of a string Narendra 24YVZnzjyokEI+uTwav00BfxwlcAGOrz2d8dZdCIrZM= This is decrypted text Narendra
Output for 5.4.23
This is encrypted text of a string Narendra rcOdVphvtLezOHR8m2oJfdJw9CeMlpMQx5JlsSHnpTw= This is decrypted text Narendra
Output for 5.4.22
This is encrypted text of a string Narendra AjGUrB45Ec8ZDxXzeIV3kk7V1dd8qx9eOQOdR1YPuwY= This is decrypted text Narendra
Output for 5.4.21
This is encrypted text of a string Narendra L+eNY5yBxGwiFqRBvopNMWMHdKXk2Mtog80nXdeWrAc= This is decrypted text Narendra
Output for 5.4.20
This is encrypted text of a string Narendra w+g47rfHRKnBx4i46+EEkpn8Q17nvfbdWUtO0SpZmYw= This is decrypted text Narendra
Output for 5.4.19
This is encrypted text of a string Narendra F0HxlTC9bg4ZPje3HUQ/ivhaifynYwAnVooSC+h9eFA= This is decrypted text Narendra
Output for 5.4.18
This is encrypted text of a string Narendra dbPcjG8LvLFyhQ2IbBU7ub1QApuDK3E8MbXb+licMgA= This is decrypted text Narendra
Output for 5.4.17
This is encrypted text of a string Narendra pBzx3nHWo4kWrAhAjdwvFPVIX5SF75Elx6NBOlI4vXY= This is decrypted text Narendra
Output for 5.4.16
This is encrypted text of a string Narendra MyixJlLbxgG2h5lyrChGlxKLSNIH8peFdRaOOeML+Lg= This is decrypted text Narendra
Output for 5.4.15
This is encrypted text of a string Narendra 6XWHxF2aDIdjpmxh4zbe+4nNxES12GgEMoYOQUEGOP8= This is decrypted text Narendra
Output for 5.4.14
This is encrypted text of a string Narendra +hJBfYHBefvwM7kxyx1lGUl28oDQBbxZHwizltLqhWc= This is decrypted text Narendra
Output for 5.4.13
This is encrypted text of a string Narendra ikjG2K/6sjhjs0u2UarDz8gim0YGjcmEPNWssoi1jAM= This is decrypted text Narendra
Output for 5.4.12
This is encrypted text of a string Narendra n5xSYVei4lzXvz9EoOLWN78nKpKyENojZel9NtzgUWU= This is decrypted text Narendra
Output for 5.4.11
This is encrypted text of a string Narendra YJxOHh8ynrLVeksHuN9InFC1bRPBN3FrxdTYc0Mh0u4= This is decrypted text Narendra
Output for 5.4.10
This is encrypted text of a string Narendra l1i27gOr6z+/hadPnFUUHsTsyY5yQcKTyULlkSKLaeI= This is decrypted text Narendra