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 6fBcN
Output for 7.0.6 - 7.2.0
Fatal error: Uncaught Error: Call to undefined function mcrypt_get_iv_size() in /in/HRI03:19 Stack trace: #0 /in/HRI03(70): Encryption->__construct() #1 {main} thrown in /in/HRI03 on line 19
Process exited with code 255.
Output for 7.0.5
This is encrypted text of a string Narendra => vO9M0mE4luXKE4CAFSEr5/KBsuxPRn3O5FxQvs6J6Ck= This is decrypted text => Narendra
Output for 7.0.4
This is encrypted text of a string Narendra => 6An6zkGUq2kv8WGe4Jg31vyBbILPTKiAtVloTnlZyLc= This is decrypted text => Narendra
Output for 7.0.3
This is encrypted text of a string Narendra => ylb4mByIKNvte1cQWoe5JDgcw4W7Y0EtCbxdH1YQ+A4= This is decrypted text => Narendra
Output for 7.0.2
This is encrypted text of a string Narendra => jJAht+ZduPzswYHY2hCwJorw/OqowTFvtHMrNRQ+K3g= This is decrypted text => Narendra
Output for 7.0.1
This is encrypted text of a string Narendra => oVdwJx6VXW0iilM0XHN3JgpwnMiH9x/dR16qM50VXmg= This is decrypted text => Narendra
Output for 7.0.0
This is encrypted text of a string Narendra => MQH83IKGEVp6lQ5F8mdbanuLv3WHCqOi0BjcjGglPFk= 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/HRI03 on line 19
Process exited with code 255.
Output for 5.6.20
This is encrypted text of a string Narendra => aYS9gaFJk7F5XA54twqFhzCsOLfEW9nb620oB6WNcMw= This is decrypted text => Narendra
Output for 5.6.19
This is encrypted text of a string Narendra => HM8XG9bSJ2NyzZQcDi7TDlb3GKavjLajKXLhO9IxMWA= This is decrypted text => Narendra
Output for 5.6.18
This is encrypted text of a string Narendra => j6mQuwEeMDXTxnP9334AgjGdAPHLe8oEkdlwuMMlXck= This is decrypted text => Narendra
Output for 5.6.17
This is encrypted text of a string Narendra => QaCnE5BFTB0X3CtEDODysF4nAgVNGyo7lFd74S/Opfw= This is decrypted text => Narendra
Output for 5.6.16
This is encrypted text of a string Narendra => tsYQ3aLUsg2n+qRIiH7FVoy02/aux88ZekxA7Ehgrew= This is decrypted text => Narendra
Output for 5.6.15
This is encrypted text of a string Narendra => qYJxN0Ze8zo5gVTpptA+HSLM6gfvzcJcjHpkIS/Qm1M= This is decrypted text => Narendra
Output for 5.6.14
This is encrypted text of a string Narendra => CihVE6eKeQpYAmL+DsFq6coLuHBJxdpkyZgmxbQOujo= This is decrypted text => Narendra
Output for 5.6.13
This is encrypted text of a string Narendra => 6tbUVkNzH2Qb5Re6KVDRs70IiUIGpjKkrtNxSPP786c= This is decrypted text => Narendra
Output for 5.6.12
This is encrypted text of a string Narendra => yzIH0JkjDtL9H85Dek4VhNB5piSCFi2Aa5DcMzpjRZQ= This is decrypted text => Narendra
Output for 5.6.11
This is encrypted text of a string Narendra => n7YBz5vhFr8XrsTqt7jKrZTnxmoAKVF49bL41wLb81A= This is decrypted text => Narendra
Output for 5.6.10
This is encrypted text of a string Narendra => urBbolkm498GF4WMjsdfgnf4KBU5oo65MORIkeD8wKM= This is decrypted text => Narendra
Output for 5.6.9
This is encrypted text of a string Narendra => d5YDGJECpouEdkSj+M/6fF5o6A0I62s9yeVG84QhIh8= This is decrypted text => Narendra
Output for 5.6.8
This is encrypted text of a string Narendra => I4DqWX40tyMFKZ1j3xNYagTV4Djm39G5bskdgru8WAg= This is decrypted text => Narendra
Output for 5.5.34
This is encrypted text of a string Narendra => QvlwBAvsHmO1cLdfNe51VSdHCxwAQ7IexU0j2m+l4WY= This is decrypted text => Narendra
Output for 5.5.33
This is encrypted text of a string Narendra => krW4HBQW3z1yAC6s5p/LHyCRkYYFp54wZ9n1qEhhJDQ= This is decrypted text => Narendra
Output for 5.5.32
This is encrypted text of a string Narendra => QjOZ6O2DAEOZKqViOemR7z3B08pIJ++oDj1+wNrPZoE= This is decrypted text => Narendra
Output for 5.5.31
This is encrypted text of a string Narendra => EOLeOYglf2OegBp5LwTXA4qQujJSRN47mz2fEcaD/4Q= This is decrypted text => Narendra
Output for 5.5.30
This is encrypted text of a string Narendra => wjAj7Cb+dwS/RFqWnzyV3v7T2Uk+U2/nB87v/aw7wO4= This is decrypted text => Narendra
Output for 5.5.29
This is encrypted text of a string Narendra => UoOpr7Bldcchsy7kGbDZjl5IuFtmCR0z8nXKdJmkUmM= This is decrypted text => Narendra
Output for 5.5.28
This is encrypted text of a string Narendra => kh6A67l1KjEKiB6y5urWHhzxXCimDV8BSl0CTgt0Zgk= This is decrypted text => Narendra
Output for 5.5.27
This is encrypted text of a string Narendra => ElhAJCNwBpjoNZDCUJgEU76zwmzBAZrl4KmBxE+4LT0= This is decrypted text => Narendra
Output for 5.5.26
This is encrypted text of a string Narendra => 2OPIndl/YRuN0+Pv7IE1n3vAn0dDN8AcUQUxlX4b4EA= This is decrypted text => Narendra
Output for 5.5.25
This is encrypted text of a string Narendra => hI19axPzkq+Jcc8uEZ/dGWs3Q7z7Y6+eHymIs5P4QfM= This is decrypted text => Narendra
Output for 5.5.24
This is encrypted text of a string Narendra => 7A0hBT9lxQIzZ/B1OpY6o2/vFWId4UjrbDyHB3VSnSw= This is decrypted text => Narendra
Output for 5.4.45
This is encrypted text of a string Narendra => 7NtLOcMRaZt1F3TauWIcNuoH7/p1sXdMrX1X8W6LofM= This is decrypted text => Narendra
Output for 5.4.44
This is encrypted text of a string Narendra => 3ntT08dZfIJlOR041xAidjcoyu3Dyf9lr12Lc/5xasY= This is decrypted text => Narendra
Output for 5.4.43
This is encrypted text of a string Narendra => ZpoD5XP67uJwxPyZEi258y0gjxz5oneMtnyQov2j8Xg= This is decrypted text => Narendra
Output for 5.4.42
This is encrypted text of a string Narendra => WAZVM0gEioOPcRr4ZVaz8td5QBbV5QkweQcAgiu5I3k= This is decrypted text => Narendra
Output for 5.4.41
This is encrypted text of a string Narendra => OY2qn2xP9JYVOb3d1uT+K736w7NXF5ibmBaSSg/LGJs= This is decrypted text => Narendra
Output for 5.4.40
This is encrypted text of a string Narendra => 4cB0UZIAGlO7pqtri7eNutd9ujiXwuCSmJYY7G0ZOh8= This is decrypted text => Narendra
Output for 5.4.39
This is encrypted text of a string Narendra => aR4cNOIaUN0KCg10hhP06Zgt9kG+YC7IclN3wTnKomI= This is decrypted text => Narendra
Output for 5.4.38
This is encrypted text of a string Narendra => LcLlTVf2Ol1ukT/JA6XUmvLNJXyyJYpIdAHJBHPG5rI= This is decrypted text => Narendra
Output for 5.4.37
This is encrypted text of a string Narendra => YdnQI9Ur+cf1IIp0kK3dhaJHHZ3QIb4TtFJu5LP4I74= This is decrypted text => Narendra
Output for 5.4.36
This is encrypted text of a string Narendra => gFlwxGR83Ze3MHpi8pxP7/yTbTJ9uJiuhVUvSU5LK3o= This is decrypted text => Narendra
Output for 5.4.35
This is encrypted text of a string Narendra => 2TnTGskAKnSJHKbXpn6cn9ZPWe/3eHOvrwOaUaf+okc= This is decrypted text => Narendra
Output for 5.4.34
This is encrypted text of a string Narendra => Ws33H9YDJJfUFVXxoKy863ENlYrtjwqMMRxywyPG4mU= This is decrypted text => Narendra
Output for 5.4.32
This is encrypted text of a string Narendra => 17UfS4AJ69vxJB3J0ElUr1tQJtG4NNSIrsjqlBn1kuQ= This is decrypted text => Narendra
Output for 5.4.31
This is encrypted text of a string Narendra => JuHT2UA12tnGhsycqjxC7ZTjsg96WWj4B+zSuMmqgQg= This is decrypted text => Narendra
Output for 5.4.30
This is encrypted text of a string Narendra => TzHucG+dFsoNmUONEJ/JHxLkYfrK6hXIEQ+nXxC9Tb4= This is decrypted text => Narendra
Output for 5.4.29
This is encrypted text of a string Narendra => oDlThwgnmz+RQZSpMarbh+D4odg3jh/GPhA6ZcSasjU= This is decrypted text => Narendra
Output for 5.4.28
This is encrypted text of a string Narendra => pEGxRLiH6Ehrv1kjiT8PXYTBWJqtQAXM8pPqa1nzzYg= This is decrypted text => Narendra
Output for 5.4.27
This is encrypted text of a string Narendra => 0klXLVWMYGWiSwOjJWlWGTOXv5aljuj/gqKC1iOXiIc= This is decrypted text => Narendra
Output for 5.4.26
This is encrypted text of a string Narendra => gAQmPtE1v+V1mECliNsayIT3qoWkYs9TGe9q/UEJmy0= This is decrypted text => Narendra
Output for 5.4.25
This is encrypted text of a string Narendra => dV2BWmHOawlPvn9c35wQGXzIoNHG0ZhtrOJ/7n0Bt6A= This is decrypted text => Narendra
Output for 5.4.24
This is encrypted text of a string Narendra => c3mSUdKHnUZYdwn+me2TRTK0Ri4LR4R4Zhjzt+lid5w= This is decrypted text => Narendra
Output for 5.4.23
This is encrypted text of a string Narendra => S2gBSS50ThQsEZXw2NIDI6zTFmSWBGzIR3ZWQcZVsMg= This is decrypted text => Narendra
Output for 5.4.22
This is encrypted text of a string Narendra => /EEh6vMV9tOigJ7wOy4z/PP4Du79BGdF8IsnM/nxPAo= This is decrypted text => Narendra
Output for 5.4.21
This is encrypted text of a string Narendra => 2rumYKVDPYnvSCah3eebl3ypbfcv5C4jk5Fuudjqv9M= This is decrypted text => Narendra
Output for 5.4.20
This is encrypted text of a string Narendra => PtzXW38eMQRgbYS9vBV6EB5nHm24TFfV92/ANHdxOVo= This is decrypted text => Narendra
Output for 5.4.19
This is encrypted text of a string Narendra => ISE0AIa5SXXZr9sVQlxKrav3OzV5o0xvaBimuxHnVVU= This is decrypted text => Narendra
Output for 5.4.18
This is encrypted text of a string Narendra => HflxffE3QCs9JMJ1k2F8kUFVEHohXy1SOL7vrcbbTTc= This is decrypted text => Narendra
Output for 5.4.17
This is encrypted text of a string Narendra => 8hvWbqCZuoK8bQBru8KoaQhUDjid84c6rp8cmaI6qWk= This is decrypted text => Narendra
Output for 5.4.16
This is encrypted text of a string Narendra => WRNnikg53e/uRpy3OBuotWb10xeJ6ujzRt14AX6KUcM= This is decrypted text => Narendra
Output for 5.4.15
This is encrypted text of a string Narendra => aKHT/Z/rrIc1FM/1tiS+TtyPfgAiUcqQmlB9Si1P4eY= This is decrypted text => Narendra
Output for 5.4.14
This is encrypted text of a string Narendra => XUoKw2Znn+O0JzIW50i8B1JmUk1h8SiJqd7qt7BBJOA= This is decrypted text => Narendra
Output for 5.4.13
This is encrypted text of a string Narendra => SGsQlDFeTNX2+HkNuwYU0o1mAztxWwOLUzzvxNyCuJw= This is decrypted text => Narendra
Output for 5.4.12
This is encrypted text of a string Narendra => oroordano7GQZhYCmM7zoLB+Bq429tj+4z7pUalZ6xM= This is decrypted text => Narendra
Output for 5.4.11
This is encrypted text of a string Narendra => fEhPN2FUWdS4WmWw0uPjKTRMU+aJzRl631TYb12EAS8= This is decrypted text => Narendra
Output for 5.4.10
This is encrypted text of a string Narendra => yOqe2DsRmK3D7IFom9paeHswscbALPk4cl6dPRJ92mc= This is decrypted text => Narendra